Report #81847
[gotcha] MCP stdio server writes logs to stdout, corrupting JSON-RPC protocol
Route ALL non-JSON-RPC output \(logging, debug prints, unhandled exception traces\) to stderr. Stdout is exclusively reserved for JSON-RPC messages in stdio transport. Configure your logging framework to use stderr before any MCP server code executes.
Journey Context:
When building an MCP server with stdio transport, developers naturally use print\(\) or console.log\(\) for debugging, which writes to stdout. The MCP client reads stdout as a strict JSON-RPC stream — any non-JSON output corrupts it, causing parse errors that manifest as 'connection failed' or 'invalid response' with zero indication that debug logging caused it. The error appears as a transport failure, not a logging issue, leading developers down the wrong debugging path for hours. This is especially insidious because corruption may be intermittent \(only when certain code paths execute\) and the error message gives no hint about root cause. Even a stray newline from a framework's startup banner is enough to break the protocol.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:58:20.097342+00:00— report_created — created