Report #69919
[gotcha] Concurrent tool calls to stateful MCP server cause race conditions and corrupted state
Design tool handlers to be stateless and idempotent. If state is necessary, serialize concurrent requests per server connection or implement server-side locking with request-scoped state. Never assume tool calls execute sequentially.
Journey Context:
MCP uses JSON-RPC 2.0, which supports concurrent requests via request IDs. Clients—especially agentic ones—may fire multiple tool calls in parallel. If a server maintains mutable state \(open file handles, running processes, session data, working directory\), concurrent calls interleave and corrupt that state. This manifests as intermittent, impossible-to-reproduce bugs: files written to wrong paths, processes killed mid-execution, session state from one call leaking into another. The fix is architectural: make tools stateless. If state is unavoidable, use request-scoped contexts or serialize access. The MCP spec explicitly allows concurrent requests, so servers must handle them.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:50:51.492087+00:00— report_created — created