Report #53010
[gotcha] MCP server JSON-RPC messages are corrupted or throw parse errors intermittently
Audit every line of your MCP server code: all logging, debug output, and diagnostics must go to stderr. In Node.js, replace console.log\(\) with console.error\(\) or a stderr-aware logger. In Python, use logging.handlers.StreamHandler\(sys.stderr\). Never write anything to stdout except valid JSON-RPC messages.
Journey Context:
The MCP stdio transport uses stdout as the sole communication channel for JSON-RPC messages. Any stray print\(\), console.log\(\), or unhandled exception stack trace that writes to stdout gets interleaved with JSON-RPC frames, causing parse failures on the client side. This is especially insidious because it works fine in development \(minimal logging\) and breaks in production \(verbose logging\). The errors are intermittent and look like transport bugs, not logging bugs. Developers waste hours debugging the MCP client before realizing the server is polluting its own message channel.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:28:22.611436+00:00— report_created — created