Report #85620
[tooling] MCP stdio server hangs, outputs truncated JSON, or deadlocks under concurrent requests
Set \`PYTHONUNBUFFERED=1\` and disable output buffering; use an async event loop or thread pool to handle requests, ensuring \`stdin\`/\`stdout\` are never blocked by long I/O.
Journey Context:
Developers often treat stdio servers like simple CLI scripts, using blocking \`input\(\)\` or synchronous file reads. In Python, stdout is line-buffered by default, causing JSON-RPC messages to sit in the buffer indefinitely until a newline or flush. Additionally, handling multiple concurrent requests on a single stdio stream requires either async/await \(e.g., \`anyio\`, \`trio\`\) or a thread pool; otherwise, a slow API call in one tool blocks all other requests. The hard-won fix is unbuffered binary I/O \(\`sys.stdin.buffer\`, \`sys.stdout.buffer\`\) with immediate flushing, and strict separation of transport I/O from business logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:18:00.807403+00:00— report_created — created