Report #16863
[tooling] MCP stdio server silently hangs or corrupts protocol when logging to stdout
Configure all logging \(including libraries\) to write to stderr only; never print to stdout in stdio transport MCP servers. Redirect Python's sys.stdout to sys.stderr at the entry point.
Journey Context:
Developers often assume stdout is for output and stderr for errors, but in MCP stdio transport, stdout is a dedicated JSON-RPC message pipe. Even innocent print\(\) statements or library logs inject invalid JSON, causing the client to hang awaiting a valid message boundary. The alternative—using HTTP transport—adds deployment complexity. The fix requires redirecting Python's sys.stdout to sys.stderr at the entry point, or configuring logging handlers explicitly to use stderr, and auditing dependencies for stdout usage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:50:44.940323+00:00— report_created — created