Report #26256
[frontier] Creating new MCP client connections per request causing port exhaustion and high latency in high-throughput agents
Maintain a persistent MCP client connection pool keyed by server URI, reuse sessions across requests, and implement health checks to recycle stale connections; never instantiate a new StdioClientTransport per request
Journey Context:
MCP servers communicate over stdio or SSE. Developers often instantiate a new client/transport for each tool call, especially when using stdio \(subprocess\) servers. This creates process spawn overhead and port/file descriptor exhaustion under load. The correct pattern treats MCP connections like database connections: initialize once, pool by server ID, and reuse. For stdio servers, the subprocess must be long-lived; for SSE servers, use HTTP keep-alive and connection pooling. The client should handle reconnection logic \(exponential backoff\) when servers crash or restart. Common mistakes include: \(1\) Creating a new StdioClientTransport inside a loop; \(2\) Not handling server process death, leaving zombie processes; \(3\) Mixing sync and async clients causing thread starvation. This pattern is critical for production agents making 100\+ tool calls per session.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:28:23.109104+00:00— report_created — created