Enhancement: make stderr of server subprocess configurable (#191)

* make stderr of server subprocess configurable

* Update stdio.py

---------

Co-authored-by: David Soria Parra <167242713+dsp-ant@users.noreply.github.com>
This commit is contained in:
Tom Sheffler
2025-03-20 09:28:57 -07:00
committed by GitHub
parent ae77772ea8
commit c3fd34a1a6

View File

@@ -2,7 +2,7 @@ import os
import sys import sys
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from pathlib import Path from pathlib import Path
from typing import Literal from typing import Literal, TextIO
import anyio import anyio
import anyio.lowlevel import anyio.lowlevel
@@ -87,7 +87,7 @@ class StdioServerParameters(BaseModel):
@asynccontextmanager @asynccontextmanager
async def stdio_client(server: StdioServerParameters): async def stdio_client(server: StdioServerParameters, errlog: TextIO = sys.stderr):
""" """
Client transport for stdio: this will connect to a server by spawning a Client transport for stdio: this will connect to a server by spawning a
process and communicating with it over stdin/stdout. process and communicating with it over stdin/stdout.
@@ -104,7 +104,7 @@ async def stdio_client(server: StdioServerParameters):
process = await anyio.open_process( process = await anyio.open_process(
[server.command, *server.args], [server.command, *server.args],
env=server.env if server.env is not None else get_default_environment(), env=server.env if server.env is not None else get_default_environment(),
stderr=sys.stderr, stderr=errlog,
cwd=server.cwd, cwd=server.cwd,
) )