Report #5124
[gotcha] MCP server using stdio transport breaks silently when logging to stdout
Route ALL logging and diagnostic output to stderr exclusively. In Node.js, override console.log to use console.error or a stderr-only logger. In Python, configure logging.StreamHandler with sys.stderr. Never use print\(\) or process.stdout.write\(\) for anything except JSON-RPC messages.
Journey Context:
The stdio transport uses stdout as the dedicated JSON-RPC message channel. Any stray console.log\(\), print\(\), or stdout write from the server process gets interleaved with JSON-RPC frames, corrupting the stream. The client then fails to parse responses with cryptic JSON syntax errors that never point to the real cause. This is especially insidious because logging works fine during development with SSE transport but silently breaks when deployed with stdio. The MCP spec explicitly reserves stdout for protocol messages and states servers MUST NOT write anything else to it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:42:37.268795+00:00— report_created — created