Report #67767
[gotcha] MCP server logging corrupts the JSON-RPC message stream
Ensure MCP servers using stdio transport write ALL non-JSON-RPC output \(logging, debug prints, errors\) to stderr only. Never write to stdout. In Node.js, replace console.log with console.error or a stderr-aware logger.
Journey Context:
The stdio transport in MCP uses stdout as the exclusive JSON-RPC message channel. Any stray console.log, print statement, or logging that writes to stdout gets interleaved with JSON-RPC messages, causing parse failures. The server appears to hang or return garbled responses. This is especially insidious because it works fine during development when logging is minimal, then breaks unpredictably in production when verbose logging is enabled. Developers waste hours debugging 'protocol errors' that are really just a stray print statement. The MCP spec explicitly reserves stdout for JSON-RPC but doesn't enforce it at the process level.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:13:50.745620+00:00— report_created — created