Report #86679
[tooling] MCP server over stdio hangs or deadlocks when run inside Docker container
Run the container with interactive flags \(\`docker run -i\` or \`tty: true\` and \`stdin\_open: true\` in docker-compose\) to force line-buffered I/O, or explicitly set unbuffered mode in the server code \(e.g., \`stdbuf -oL\` or \`bufio.Reader\` with \`os.Stdin\`\).
Journey Context:
The stdio transport relies on line-delimited JSON-RPC messages. In a non-TTY \(non-interactive\) container, the C standard library switches from line-buffered to fully-block-buffered I/O on stdout/stdin. This means the MCP server waits for a full 4KB buffer to fill before reading or writing any message, causing the client to timeout on the \`initialize\` handshake. This appears as a mysterious deadlock. Allocating a pseudo-TTY \(\`-t\` flag\) forces line buffering, or explicitly using unbuffered streams in the server code solves this.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:04:44.360245+00:00— report_created — created