Let Client take StdioServerParameters directly (#3321)

This commit is contained in:
Max 2026-08-17 14:31:21 +01:00 • committed by GitHub
commit e473cca6a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@
from __future__ import annotations
import contextvars
import sys
from collections.abc import AsyncIterator, Iterator
from contextlib import asynccontextmanager, contextmanager
from unittest.mock import patch
@ -35,7 +36,7 @@ from mcp_types import (
from mcp_types.version import LATEST_HANDSHAKE_VERSION
from pydantic import FileUrl
from mcp import MCPDeprecationWarning, MCPError
from mcp import MCPDeprecationWarning, MCPError, StdioServerParameters
from mcp.client._memory import InMemoryTransport
from mcp.client._transport import TransportStreams
from mcp.client.client import Client
@ -414,6 +415,24 @@ async def test_client_uses_transport_directly(app: MCPServer):
)
async def test_client_with_stdio_parameters_launches_the_server_as_a_subprocess() -> None:
"""SDK-defined: `Client` routes a `StdioServerParameters` through `stdio_client`, so entering it
spawns the command and negotiates over the child's stdin/stdout. The process boundary is the
behaviour, hence a real child interpreter running a one-line `MCPServer`."""
params = StdioServerParameters(
command=sys.executable,
args=["-c", "from mcp.server import MCPServer; MCPServer('stdio-demo').run()"],
)
# Wider than the standard 5: a cold interpreter start plus `import mcp.server` in the child takes
# seconds on a loaded Windows runner, and exit may wait out stdio_client's terminate/kill
# escalation (PROCESS_TERMINATION_TIMEOUT + FORCE_KILL_TIMEOUT + reap, ~6s) if the child is slow.
with anyio.fail_after(20):
async with Client(params) as client:
assert client.server_info is not None
assert client.server_info.name == "stdio-demo"
assert (await client.list_tools()).tools == []
_TEST_CONTEXTVAR = contextvars.ContextVar("test_var", default="initial")