From 8ee7455692049f6e9d88527440903771191c61cb Mon Sep 17 00:00:00 2001 From: Bortlesboat Date: Thu, 19 Mar 2026 22:22:59 -0400 Subject: [PATCH] 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 --- src/mcp/client/stdio.py | 4 ++-- src/mcp/os/win32/utilities.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mcp/client/stdio.py b/src/mcp/client/stdio.py index 902dc8576..531ab480b 100644 --- a/src/mcp/client/stdio.py +++ b/src/mcp/client/stdio.py @@ -102,7 +102,7 @@ class StdioServerParameters(BaseModel): @asynccontextmanager -async def stdio_client(server: StdioServerParameters, errlog: TextIO = sys.stderr): +async def stdio_client(server: StdioServerParameters, errlog: TextIO | int = sys.stderr): """Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout. """ @@ -230,7 +230,7 @@ async def _create_platform_compatible_process( command: str, args: list[str], env: dict[str, str] | None = None, - errlog: TextIO = sys.stderr, + errlog: TextIO | int = sys.stderr, cwd: Path | str | None = None, ): """Creates a subprocess in a platform-compatible way. diff --git a/src/mcp/os/win32/utilities.py b/src/mcp/os/win32/utilities.py index 6f68405f7..aeb5e8e50 100644 --- a/src/mcp/os/win32/utilities.py +++ b/src/mcp/os/win32/utilities.py @@ -138,7 +138,7 @@ async def create_windows_process( command: str, args: list[str], env: dict[str, str] | None = None, - errlog: TextIO | None = sys.stderr, + errlog: TextIO | int | None = sys.stderr, cwd: Path | str | None = None, ) -> Process | FallbackProcess: """Creates a subprocess in a Windows-compatible way with Job Object support. @@ -155,7 +155,7 @@ async def create_windows_process( command (str): The executable to run args (list[str]): List of command line arguments env (dict[str, str] | None): Environment variables - errlog (TextIO | None): Where to send stderr output (defaults to sys.stderr) + errlog (TextIO | int | None): Where to send stderr output (defaults to sys.stderr) cwd (Path | str | None): Working directory for the subprocess Returns: @@ -196,7 +196,7 @@ async def _create_windows_fallback_process( command: str, args: list[str], env: dict[str, str] | None = None, - errlog: TextIO | None = sys.stderr, + errlog: TextIO | int | None = sys.stderr, cwd: Path | str | None = None, ) -> FallbackProcess: """Create a subprocess using subprocess.Popen as a fallback when anyio fails.