Report #4789
[gotcha] Stateful MCP servers break when clients spawn multiple concurrent STDIO connections
Design MCP servers as stateless request handlers. If state is required, persist it externally \(e.g., filesystem, database\) keyed by a session ID passed in the tool arguments, rather than relying on in-memory global variables.
Journey Context:
Developers often build STDIO-based MCP servers with in-memory state \(like a loaded AST or database connection\). However, clients might spawn multiple server instances or send concurrent requests over the same transport. In-memory state gets out of sync or is lost between requests. Stateless design aligns with the MCP transport model and prevents bizarre, unreproducible bugs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:04:43.337430+00:00— report_created — created