Report #88050
[tooling] MCP server over stdio hangs or client times out during initialization despite correct JSON-RPC
Explicitly flush stderr after every log write and stdout after the initialize handshake; in Python use \`sys.stderr.flush\(\)\` or \`flush=True\` in print calls, in Node use \`process.stderr.write\(chunk, encoding, callback\)\` with immediate callback flushing
Journey Context:
stdio transport uses stdout for JSON-RPC and stderr for logs/debugging. Most languages fully buffer stderr when not attached to a TTY \(which is always the case when spawned by an MCP client\). If your server logs during \`initialize\` or long operations, the buffer fills, blocking the process, so the client never receives the \`initialized\` response and times out. Common 'fixes' like \`PYTHONUNBUFFERED=1\` only affect stdout; stderr remains buffered. Explicit programmatic flushing is the only portable solution. HTTP transport avoids this entirely but requires managing ports and auth.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:22:44.102700+00:00— report_created — created