Skip to content

Commit 0f2c132

Browse files
committed
Annotate stdio_client's return type with TransportStreams
stdio_client now carries the same AsyncGenerator[TransportStreams, None] annotation as streamable_http_client, so it formally satisfies the Transport protocol instead of leaking anyio's concrete memory-stream types. Also adds the missing -> None on FallbackProcess.__init__ and retypes the test helper to the ReadStream protocol.
1 parent b7c2809 commit 0f2c132

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/mcp/client/stdio.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313
import os
1414
import sys
15+
from collections.abc import AsyncGenerator
1516
from contextlib import asynccontextmanager, suppress
1617
from pathlib import Path
1718
from typing import Literal, TextIO
@@ -23,6 +24,7 @@
2324
from pydantic import BaseModel, Field
2425

2526
from mcp import types
27+
from mcp.client._transport import TransportStreams
2628
from mcp.os.posix.utilities import terminate_posix_process_tree
2729
from mcp.os.win32.utilities import (
2830
ServerProcess,
@@ -129,7 +131,9 @@ class StdioServerParameters(BaseModel):
129131

130132

131133
@asynccontextmanager
132-
async def stdio_client(server: StdioServerParameters, errlog: TextIO = sys.stderr):
134+
async def stdio_client(
135+
server: StdioServerParameters, errlog: TextIO = sys.stderr
136+
) -> AsyncGenerator[TransportStreams, None]:
133137
"""Client transport for stdio: this will connect to a server by spawning a
134138
process and communicating with it over stdin/stdout.
135139

src/mcp/os/win32/utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class FallbackProcess:
8282
so that MCP clients expecting async streams can work properly.
8383
"""
8484

85-
def __init__(self, popen_obj: subprocess.Popen[bytes]):
85+
def __init__(self, popen_obj: subprocess.Popen[bytes]) -> None:
8686
self.popen: subprocess.Popen[bytes] = popen_obj
8787
stdin = popen_obj.stdin
8888
stdout = popen_obj.stdout

tests/client/test_stdio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from anyio.streams.memory import MemoryObjectReceiveStream
3030

3131
from mcp.client import stdio
32+
from mcp.client._transport import ReadStream
3233
from mcp.client.session import ClientSession
3334
from mcp.client.stdio import (
3435
_EXIT_POLL_INTERVAL,
@@ -224,7 +225,7 @@ def _line(message: JSONRPCMessage) -> bytes:
224225
return (message.model_dump_json(by_alias=True, exclude_unset=True) + "\n").encode()
225226

226227

227-
async def _next_message(read_stream: MemoryObjectReceiveStream[SessionMessage | Exception]) -> JSONRPCMessage:
228+
async def _next_message(read_stream: ReadStream[SessionMessage | Exception]) -> JSONRPCMessage:
228229
received = await read_stream.receive()
229230
assert isinstance(received, SessionMessage)
230231
return received.message

0 commit comments

Comments
 (0)