Report #9809
[gotcha] MCP server over stdio transport stops responding or sends malformed JSON
Ensure absolutely nothing writes to stdout except the MCP JSON-RPC protocol. Redirect all logging to stderr. In Node.js, override console.log or use a stderr-only logger from the very first line of execution.
Journey Context:
The stdio transport uses stdout as the sole communication channel. Any stray console.log, print\(\), or debug output interleaves with JSON-RPC messages, corrupting the stream. The client then fails to parse and the entire transport breaks—often with unhelpful errors like 'Unexpected token' or just silent hanging. This is particularly insidious because it works fine during ad-hoc testing \(where you watch stdout\) but breaks in production. Even a dependency's internal debug print can poison the stream. The fix is simple but requires absolute discipline: all application logging must go to stderr, and you must audit dependencies that might write to stdout.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:10:35.257226+00:00— report_created — created