Skip to content

Commit 131dcc4

Browse files
author
Rudrendu
committed
fix: allow integer file descriptors for errlog in stdio_client
Github-Issue: #1806
1 parent cf4e435 commit 131dcc4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/mcp/client/stdio.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,15 @@ class StdioServerParameters(BaseModel):
102102

103103

104104
@asynccontextmanager
105-
async def stdio_client(server: StdioServerParameters, errlog: TextIO = sys.stderr):
105+
async def stdio_client(server: StdioServerParameters, errlog: TextIO | int = sys.stderr):
106106
"""Client transport for stdio: this will connect to a server by spawning a
107107
process and communicating with it over stdin/stdout.
108+
109+
Args:
110+
server: Parameters for the server process to spawn.
111+
errlog: Where to send stderr output from the server process. Accepts a
112+
text stream (e.g. ``sys.stderr``) or an integer file descriptor,
113+
including ``subprocess.DEVNULL`` to discard stderr entirely.
108114
"""
109115
read_stream: MemoryObjectReceiveStream[SessionMessage | Exception]
110116
read_stream_writer: MemoryObjectSendStream[SessionMessage | Exception]
@@ -230,7 +236,7 @@ async def _create_platform_compatible_process(
230236
command: str,
231237
args: list[str],
232238
env: dict[str, str] | None = None,
233-
errlog: TextIO = sys.stderr,
239+
errlog: TextIO | int = sys.stderr,
234240
cwd: Path | str | None = None,
235241
):
236242
"""Creates a subprocess in a platform-compatible way.

src/mcp/os/win32/utilities.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async def create_windows_process(
138138
command: str,
139139
args: list[str],
140140
env: dict[str, str] | None = None,
141-
errlog: TextIO | None = sys.stderr,
141+
errlog: TextIO | int | None = sys.stderr,
142142
cwd: Path | str | None = None,
143143
) -> Process | FallbackProcess:
144144
"""Creates a subprocess in a Windows-compatible way with Job Object support.
@@ -155,7 +155,9 @@ async def create_windows_process(
155155
command (str): The executable to run
156156
args (list[str]): List of command line arguments
157157
env (dict[str, str] | None): Environment variables
158-
errlog (TextIO | None): Where to send stderr output (defaults to sys.stderr)
158+
errlog (TextIO | int | None): Where to send stderr output. Accepts a text
159+
stream, an integer file descriptor (e.g. ``subprocess.DEVNULL``), or
160+
``None`` (defaults to sys.stderr)
159161
cwd (Path | str | None): Working directory for the subprocess
160162
161163
Returns:
@@ -196,7 +198,7 @@ async def _create_windows_fallback_process(
196198
command: str,
197199
args: list[str],
198200
env: dict[str, str] | None = None,
199-
errlog: TextIO | None = sys.stderr,
201+
errlog: TextIO | int | None = sys.stderr,
200202
cwd: Path | str | None = None,
201203
) -> FallbackProcess:
202204
"""Create a subprocess using subprocess.Popen as a fallback when anyio fails.

0 commit comments

Comments
 (0)