Expose optional stdin/stdout on MCPServer stdio entrypoints#2343
Open
mangelajo wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
Expose optional stdin/stdout on MCPServer stdio entrypoints#2343mangelajo wants to merge 3 commits intomodelcontextprotocol:mainfrom
mangelajo wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
MCPServer.run_stdio_async and run(..., transport="stdio") now accept optional async text streams, matching mcp.server.stdio.stdio_server. This supports hosts that redirect process stdout for logging while keeping a dedicated MCP JSON-RPC stream. Made-with: Cursor
Made-with: Cursor
4 tasks
mangelajo
commented
Mar 25, 2026
The SSE and streamable-http overloads declare transport-specific params but the implementation catches them all via **kwargs. Follow the same pattern for stdin/stdout so the implementation signature stays uniform. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mcp.server.stdio.stdio_serveralready supports optionalstdinandstdout. This PR threads those parameters throughMCPServer.run_stdio_asyncand thestdiobranch ofMCPServer.run, so applications can use the public API instead of callingstdio_servermanually and depending on internal wiring.Motivation
MCP over stdio is JSON-RPC on a dedicated pair of streams. In real processes, fd 1 is also used for logging,
print(), subprocesses, and native code. Any extra bytes on the protocol stream corrupt JSON-RPC and break clients.A common pattern is to duplicate the real stdout fd for MCP-only I/O and redirect fd 1 (and often
sys.stdout) to stderr so other output stays off the wire. That requires passing customstdin/stdoutinto the same code path the server uses for stdio.stdio_serveralready accepts them; this exposes the same capability onMCPServer.Testing
Adds
tests/server/mcpserver/test_run_stdio_custom_streams.py, which asserts custom streams are forwarded tostdio_server(withstdio_serverand low-levelrunstubbed).Example consumer
Downstream servers jumpstarter-dev/jumpstarter#383 need this to keep logs and tooling output off the MCP stream while staying on supported APIs.
We have a lot of logging originating from gRPC and other libraries that we want to keep out of the channel, and we are using async io.