Report #25528
[gotcha] MCP stdio server writes logs to stdout, breaking JSON-RPC silently
Ensure all MCP server logging goes to stderr, never stdout. Configure logging libraries to write to stderr or a file. In Node.js, use console.error or process.stderr; in Python, configure logging.StreamHandler with sys.stderr. Never use print\(\) or console.log\(\) for debug output in an MCP stdio server.
Journey Context:
The stdio transport uses stdout as the dedicated JSON-RPC message channel. Any non-JSON-RPC output on stdout corrupts the message stream. This is especially insidious because the server appears to work during development — logs are visible in the terminal — but fails when parsed by the MCP client. The corruption can be partial: a log line interleaved with a JSON message causes a parse error on the subsequent message, making it look like a completely different tool is broken. Developers waste hours debugging the wrong tool. The MCP spec explicitly reserves stdout for protocol messages only.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T21:15:03.333083+00:00— report_created — created