Report #69776
[tooling] MCP stdio server hangs or timeouts during initialization despite correct JSON-RPC implementation
Force unbuffered or line-buffered stdout in the server process before writing any JSON-RPC messages \(e.g., \`setvbuf\(stdout, NULL, \_IOLBF, 0\)\` in C, \`PYTHONUNBUFFERED=1\` for Python, or \`process.stdout.setDefaultEncoding\('utf8'\)\` with immediate flush in Node.js\).
Journey Context:
The MCP stdio transport uses newline-delimited JSON. Most languages default to fully buffered stdout when piped, causing the server to hold the 'initialized' notification in a buffer indefinitely while the client waits for a response. This manifests as random hangs that disappear when running interactively. The fix must explicitly set buffering mode at process startup, not just flush after each message, because the stdio stream itself must be in line-buffered mode.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:36:08.227254+00:00— report_created — created