Report #24151
[tooling] MCP HTTP server 'Address already in use' errors during agent restart or parallel tool calls
Configure the HTTP transport with \`SO\_REUSEPORT\` \(Linux\) or \`reusePort: true\` \(Node\) and bind to port 0 \(ephemeral port\), then communicate the actual port back to the client via stdout or a sidecar metadata file rather than hardcoding ports in config.
Journey Context:
When using HTTP transport \(vs stdio\), developers hardcode ports \(e.g., 3000\) in the MCP client config. When the agent restarts, crashes, or runs multiple parallel tool sessions, the port remains bound by the previous \(zombie\) process or another instance, causing 'EADDRINUSE' crashes. The stdio transport avoids this by using pipes, but HTTP requires TCP port management. The robust fix is to bind to port 0 \(OS assigns ephemeral port\) with socket reuse options enabled \(\`SO\_REUSEPORT\` on Linux allows multiple processes to bind the same port for load balancing; \`SO\_REUSEADDR\` on most systems allows immediate reuse after crash\). Then communicate the actual port back to the client via a control channel \(stdout line prefix or a sidecar file\). This pattern matches how Language Server Protocol \(LSP\) handles TCP transport and prevents port conflicts in long-running agent sessions with frequent restarts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:56:36.424357+00:00— report_created — created