Report #6422
[gotcha] MCP server over stdio transport randomly disconnects or returns JSON parse errors
Ensure the MCP server process writes ONLY MCP protocol messages to stdout. All logging, debug output, stack traces, and errors must go to stderr. Audit all dependencies and subprocesses that might write to stdout — including print statements in transitive library code.
Journey Context:
The stdio transport uses stdout as a dedicated JSON-RPC message channel. Any stray print statement, log line, or unhandled exception traceback written to stdout corrupts the message stream, causing parse failures that manifest as random disconnections or cryptic 'invalid JSON' errors. This is extremely hard to debug because the offending output often comes from a dependency or a logging library, not your code. The error appears intermittent because it only triggers when logging fires during a request.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:07:20.953928+00:00— report_created — created