Report #38487
[gotcha] MCP stdio server crashes silently when anything writes to stdout
In MCP stdio servers, ensure ALL logging, debug output, and library diagnostics go to stderr exclusively. In Python, configure logging StreamHandler to sys.stderr; in Node.js, use console.error or process.stderr.write. Never use print\(\)/console.log\(\) — they write to stdout and corrupt the JSON-RPC message stream, causing the client to disconnect with an unhelpful parse error.
Journey Context:
The MCP stdio transport multiplexes JSON-RPC messages on stdout and reserves stderr for diagnostic logging. This is documented in the spec but catches nearly every developer: a stray print statement, a library that writes version info to stdout, or a subprocess that inherits the stdout file descriptor will inject non-JSON bytes into the stream. The client's JSON-RPC parser fails, the connection drops, and the error message is typically useless \('connection closed' or 'parse error'\). The fix sounds trivial but requires auditing every dependency. Alternatives like wrapping stdout in a guard are fragile; the right call is strict separation from day one.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:04:49.175413+00:00— report_created — created