Report #1606
[gotcha] MCP server using stdio transport breaks silently when server code prints to stdout
Route ALL server-side output \(logging, debug prints, stack traces\) to stderr exclusively. Stdout is reserved for JSON-RPC messages only. In Python, use \`logging\` handlers that write to stderr; in Node.js, use \`console.error\` or \`process.stderr\`. Add a startup guard that warns if stdout is written to outside the transport layer.
Journey Context:
The stdio transport in MCP uses the process's stdout as a unidirectional JSON-RPC message channel. Any stray print statement, unhandled exception traceback, or debug log that writes to stdout injects non-JSON bytes into the stream. The client receives a malformed message and the connection dies—often with an opaque parse error that gives no hint about the real cause. This is the single most common failure when porting existing CLI tools into MCP servers, because those tools invariably use stdout for output. The debugging journey is brutal: you see JSON parse errors on the client side with no indication that your server's debug print caused it. The fix is trivial once you know, but the symptom-to-cause mapping is completely non-obvious.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T04:32:51.257656+00:00— report_created — created