From 467f30756804ffeaabff28333ff80ff1a1296b22 Mon Sep 17 00:00:00 2001 From: Thomas Sheffler Date: Wed, 5 Feb 2025 11:06:12 -0800 Subject: [PATCH 1/2] make stderr of server subprocess configurable --- src/mcp/client/stdio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcp/client/stdio.py b/src/mcp/client/stdio.py index 2eaa3475..998a67f3 100644 --- a/src/mcp/client/stdio.py +++ b/src/mcp/client/stdio.py @@ -83,7 +83,7 @@ class StdioServerParameters(BaseModel): @asynccontextmanager -async def stdio_client(server: StdioServerParameters): +async def stdio_client(server: StdioServerParameters, errlog=sys.stderr): """ Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout. @@ -100,7 +100,7 @@ async def stdio_client(server: StdioServerParameters): process = await anyio.open_process( [server.command, *server.args], env=server.env if server.env is not None else get_default_environment(), - stderr=sys.stderr, + stderr=errlog, ) async def stdout_reader(): From 76872502312d1fddadeb6ae979deced56c7820ba Mon Sep 17 00:00:00 2001 From: David Soria Parra <167242713+dsp-ant@users.noreply.github.com> Date: Thu, 20 Mar 2025 16:10:25 +0000 Subject: [PATCH 2/2] Update stdio.py --- src/mcp/client/stdio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcp/client/stdio.py b/src/mcp/client/stdio.py index 69656d10..ac8ae7e7 100644 --- a/src/mcp/client/stdio.py +++ b/src/mcp/client/stdio.py @@ -2,7 +2,7 @@ import sys from contextlib import asynccontextmanager from pathlib import Path -from typing import Literal +from typing import Literal, TextIO import anyio import anyio.lowlevel @@ -87,7 +87,7 @@ class StdioServerParameters(BaseModel): @asynccontextmanager -async def stdio_client(server: StdioServerParameters, errlog=sys.stderr): +async def stdio_client(server: StdioServerParameters, errlog: TextIO = sys.stderr): """ Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout.