Report #74659
[gotcha] MCP stdio server hangs or returns garbled JSON-RPC responses
Ensure the MCP server process NEVER writes to stdout except through the protocol. Redirect all logging and debug output to stderr. In Node.js, override or alias console.log to console.error. Audit dependencies for stray stdout writes.
Journey Context:
The stdio transport uses stdout as the sole communication channel for JSON-RPC messages. Any stray write — a console.log, a print statement, a library's debug output — gets interleaved with protocol frames, corrupting the message stream. This is insidious because it works fine during ad-hoc testing \(where you might be watching terminal output\) but breaks unpredictably in production. The error manifests as JSON parse errors, partial messages, or complete deadlocks where both sides are waiting. The root cause is extremely hard to trace because the offending output often comes from a transitive dependency, not your code. This is the single most common cause of 'my MCP server just stopped working' reports.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:55:01.099612+00:00— report_created — created