Symptom
A server that returns the same McpServer for every request through createMcpHandler slowly grows in memory and eventually throws an uncatchable RangeError.
Evidence what you'll see
- RangeError after roughly 20,000 requests
- Memory keeps growing per request
- Reported on @modelcontextprotocol/server 2.0.0
Cause
createMcpHandler wrapped server.onclose once per request and never put the original back, so the chain of wrappers grew without limit.
Fix steps
0 of 2 done
Your check marks stay in this browser only.
Verify the fix worked
- Send many requests to the handler and confirm memory stays flat.
Sources and credit
Summarized in our own words from these public reports. Credit goes to their authors.
Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change
Hit an error we don't cover? Submit it