Report #29113
[tooling] MCP stdio server fails with JSON parse errors or hangs because diagnostic logs are written to stdout
Redirect all logging to stderr \(file descriptor 2\) before starting MCP server; in Node.js use \`console.error\` or override \`process.stdout.write\`, in Python configure \`logging\` to \`sys.stderr\` only
Journey Context:
MCP stdio transport multiplexes JSON-RPC messages over stdout. Developers often add \`console.log\` or \`print\(\)\` for debugging. When the server process starts, any text written to stdout \(file descriptor 1\) that isn't valid JSON-RPC corrupts the stream, causing the client to throw parse errors or hang waiting for a valid message boundary. This is insidious because logging works fine when running the server manually in a terminal, but breaks only when spawned as a child process with stdio pipes. The fix requires strict discipline: stdout is exclusively for MCP protocol messages; all diagnostics, startup messages, and logs must go to stderr.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:15:39.071599+00:00— report_created — created