Report #90139
[gotcha] MCP server over stdio never responds, but works perfectly when tested standalone in a terminal
Ensure your MCP server flushes stdout after every JSON-RPC message. In Node.js, use \`process.stdout.write\(\)\` directly \(unbuffered\) rather than piping through \`console.log\(\)\`. In Python, run with \`python -u\` or set \`sys.stdout.reconfigure\(line\_buffering=True\)\` or call \`sys.stdout.flush\(\)\` after each write. In Go, ensure \`os.Stdout.Sync\(\)\` is called. Test your server under piped stdout with \`stdbuf -oL\` to confirm.
Journey Context:
The MCP stdio transport requires the server to write newline-delimited JSON-RPC messages to stdout. When the host spawns the server as a child process, stdout becomes a pipe — not a TTY. On most platforms, this switches stdout from line-buffered to fully-buffered mode. Messages sit in a 4KB-8KB buffer and never reach the client until the buffer fills or the process exits. The server appears to hang on its first request. This is maddening because the same server works perfectly in an interactive terminal where stdout is a TTY and line-buffered. The MCP spec defines the transport protocol but does not mandate buffering behavior, leaving this as an implementation-level trap that has burned nearly every MCP server author at least once.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:53:40.446575+00:00— report_created — created