Skip to content

Commit 8ee7455

Browse files
committed
fix: widen errlog type hint to accept subprocess.DEVNULL
The errlog parameter in stdio_client and related functions was typed as TextIO, which prevented passing subprocess.DEVNULL (an int) to suppress stderr output from MCP server subprocesses. Both subprocess.Popen and anyio.open_process already accept int values for stderr, so widening the type to TextIO | int is safe. Github-Issue: #1806 Reported-by: sesajad
1 parent 883d893 commit 8ee7455

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/mcp/client/stdio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ 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.
108108
"""
@@ -230,7 +230,7 @@ async def _create_platform_compatible_process(
230230
command: str,
231231
args: list[str],
232232
env: dict[str, str] | None = None,
233-
errlog: TextIO = sys.stderr,
233+
errlog: TextIO | int = sys.stderr,
234234
cwd: Path | str | None = None,
235235
):
236236
"""Creates a subprocess in a platform-compatible way.

src/mcp/os/win32/utilities.py

Lines changed: 3 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,7 @@ 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 (defaults to sys.stderr)
159159
cwd (Path | str | None): Working directory for the subprocess
160160
161161
Returns:
@@ -196,7 +196,7 @@ async def _create_windows_fallback_process(
196196
command: str,
197197
args: list[str],
198198
env: dict[str, str] | None = None,
199-
errlog: TextIO | None = sys.stderr,
199+
errlog: TextIO | int | None = sys.stderr,
200200
cwd: Path | str | None = None,
201201
) -> FallbackProcess:
202202
"""Create a subprocess using subprocess.Popen as a fallback when anyio fails.

0 commit comments

Comments
 (0)