Report #91212
[gotcha] MCP stdio server works in isolation but client hangs waiting for response
Ensure your MCP server flushes stdout after every JSON-RPC message. In Node.js, use process.stdout.write\(\) which is synchronous and unbuffered for pipes, rather than console.log\(\) which may buffer. In Python, call sys.stdout.flush\(\) after writing, or launch with python -u for unbuffered mode.
Journey Context:
MCP stdio transport writes JSON-RPC messages to stdout. But stdout is buffered by default in many runtimes. Node.js child process pipes may buffer output, and Python's stdout is line-buffered at best for non-TTY destinations. If the server writes a response but the buffer is not flushed, the client never receives it and hangs indefinitely. This is maddening to debug because: \(1\) the server code is correct, \(2\) unit tests pass when stdout goes to a TTY, \(3\) the hang only manifests in the full client-server integration over a pipe. The issue is especially common with servers that log to stderr \(which works fine and appears in logs\) but buffer their stdout responses. The spec says nothing about flushing — it is an implementation concern that bites everyone exactly once.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:41:34.211101+00:00— report_created — created