Skip to content

Commit 7ae772a

Browse files
author
Rudrendu
committed
fix: allow integer file descriptors for errlog in stdio_client
Github-Issue: #1806
1 parent a4f4ccd commit 7ae772a

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/mcp/client/stdio.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@ class StdioServerParameters(BaseModel):
112112

113113
@asynccontextmanager
114114
async def stdio_client(
115-
server: StdioServerParameters, errlog: TextIO = sys.stderr
115+
server: StdioServerParameters, errlog: TextIO | int = sys.stderr
116116
) -> AsyncGenerator[TransportStreams, None]:
117117
"""Spawns an MCP server subprocess and connects to it over stdin/stdout.
118118
119+
Args:
120+
server: Parameters for the server process to spawn.
121+
errlog: Where to send the server's stderr. Accepts a text stream
122+
(e.g. ``sys.stderr``) or an integer file descriptor, including
123+
``subprocess.DEVNULL`` to discard stderr entirely.
124+
119125
Raises:
120126
OSError: If the server process cannot be spawned.
121127
ValueError: If the spawn parameters are invalid (embedded NUL bytes).
@@ -329,7 +335,7 @@ async def _create_platform_compatible_process(
329335
command: str,
330336
args: list[str],
331337
env: dict[str, str] | None = None,
332-
errlog: TextIO = sys.stderr,
338+
errlog: TextIO | int = sys.stderr,
333339
cwd: Path | str | None = None,
334340
) -> ServerProcess:
335341
"""Spawns the server in its own kill scope.

src/mcp/os/win32/utilities.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def create_windows_process(
137137
command: str,
138138
args: list[str],
139139
env: dict[str, str] | None = None,
140-
errlog: TextIO | None = sys.stderr,
140+
errlog: TextIO | int | None = sys.stderr,
141141
cwd: Path | str | None = None,
142142
) -> Process | FallbackProcess:
143143
"""Creates a subprocess with Job Object support for tree termination.
@@ -149,6 +149,9 @@ async def create_windows_process(
149149
with it; children spawned before the assignment completes are not captured
150150
(see the inline note below).
151151
152+
errlog accepts a text stream (e.g. ``sys.stderr``), an integer file
153+
descriptor (e.g. ``subprocess.DEVNULL``), or ``None``.
154+
152155
Returns:
153156
Process | FallbackProcess: The spawned process with async stdin/stdout streams.
154157
"""
@@ -177,7 +180,7 @@ async def _create_windows_fallback_process(
177180
command: str,
178181
args: list[str],
179182
env: dict[str, str] | None = None,
180-
errlog: TextIO | None = sys.stderr,
183+
errlog: TextIO | int | None = sys.stderr,
181184
cwd: Path | str | None = None,
182185
) -> FallbackProcess:
183186
"""Spawns via subprocess.Popen and wraps it in FallbackProcess."""

0 commit comments

Comments
 (0)