Report #87751
[gotcha] MCP messages are lost or cause parse errors over stdio transport
Ensure every JSON-RPC message is written as a single line with no embedded newlines—never pretty-print JSON in stdio messages. Flush stdout immediately after each write. On the receiving side, read line-by-line and parse each complete line as one message. For SSE transport, always include the Content-Length header.
Journey Context:
The MCP stdio transport uses newline-delimited JSON: each message is exactly one line terminated by \\n. A common mistake is pretty-printing JSON with indentation and embedded newlines, which splits one logical message into multiple fragments. The receiver parses each line independently, producing parse errors on partial JSON. Another silent killer is stdout buffering: if the server writes a message but doesn't flush, it sits in the buffer and the client never receives it. This works fine in testing \(small messages, fast flushes\) but fails in production under load. The fix is simple but must be enforced consistently: single-line JSON, immediate flush, every time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:52:39.089383+00:00— report_created — created