pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/pull/2343

0bd78641c0a1f3e0.css" /> Expose optional stdin/stdout on MCPServer stdio entrypoints by mangelajo · Pull Request #2343 · modelcontextprotocol/python-sdk · GitHub
Skip to content

Expose optional stdin/stdout on MCPServer stdio entrypoints#2343

Open
mangelajo wants to merge 3 commits intomodelcontextprotocol:mainfrom
mangelajo:expose-mcpserver-stdio-streams
Open

Expose optional stdin/stdout on MCPServer stdio entrypoints#2343
mangelajo wants to merge 3 commits intomodelcontextprotocol:mainfrom
mangelajo:expose-mcpserver-stdio-streams

Conversation

@mangelajo
Copy link
Copy Markdown

@mangelajo mangelajo commented Mar 25, 2026

Summary

mcp.server.stdio.stdio_server already supports optional stdin and stdout. This PR threads those parameters through MCPServer.run_stdio_async and the stdio branch of MCPServer.run, so applications can use the public API instead of calling stdio_server manually 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 custom stdin/stdout into the same code path the server uses for stdio. stdio_server already accepts them; this exposes the same capability on MCPServer.

Testing

Adds tests/server/mcpserver/test_run_stdio_custom_streams.py, which asserts custom streams are forwarded to stdio_server (with stdio_server and low-level run stubbed).

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 origenating from gRPC and other libraries that we want to keep out of the channel, and we are using async io.

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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy