Report #79225
[tooling] MCP server over stdio hangs indefinitely when returning large tool responses \(>1MB\) or logging to stdout
When using stdio transport, never use blocking \`console.log\` or \`print\` in the main thread; use \`process.stdout.write\` in Node.js with backpressure handling \(drain event\) or \`sys.stdout.buffer\` in Python with chunked writes. If response exceeds ~4MB, switch to HTTP transport or implement resource pagination via URI templates instead of returning bulk data in tool results.
Journey Context:
Stdio transport uses stdin/stdout for JSON-RPC messages. Many languages block on stdout writes when the OS pipe buffer fills \(typically 64KB to 4MB\). If the MCP server tries to write a massive JSON blob \(e.g., reading a large file\) to stdout while the client is still processing the previous message, the buffer fills, the server blocks, and if the client is waiting for the response before consuming more, you get a deadlock. Additionally, accidental \`console.log\` debug statements inject non-JSON text into the stream, causing parse errors. The fix is to respect backpressure \(e.g., Node.js \`stream.finished\` or Python \`selector\`\), stream large data in chunks, or better yet, never return bulk data via stdio tool results—return a URI to a Resource or use pagination.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:34:17.241121+00:00— report_created — created