Report #1459
[gotcha] MCP server stdout pollution breaks JSON-RPC message framing — tool calls fail with parse errors
Never write to stdout from an MCP server process except via the official SDK transport. Route all logging, debug output, and print statements to stderr. Use the MCP SDK's built-in logging facility instead of console.log/print. Validate in CI that the server emits nothing on stdout outside of JSON-RPC messages.
Journey Context:
MCP stdio transport uses stdout for JSON-RPC message exchange: each message is a JSON object terminated by a newline. If the server process writes ANYTHING else to stdout—a debug print, a library warning, a stack trace—it corrupts the message stream. The client attempts to parse the interleaved garbage as JSON-RPC and fails with opaque parse errors. This is extremely difficult to debug because the error appears as a generic JSON parse failure, not as 'you printed to stdout.' Third-party libraries are the worst offenders: they may write to stdout without the developer realizing. The fix is a hard rule: stdout is reserved for the protocol, everything else goes to stderr or the MCP logging facility.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-14T22:33:01.952091+00:00— report_created — created