Symptom
A createMcpHandler factory that returns the same McpServer every time grows memory, then throws RangeError: Maximum call stack size exceeded after handler.close() has already resolved.
Evidence what you'll see
- The report prints
closed cleanlyand then theRangeError, so atry/catcharoundclose()does not see it. - The stack is a long chain of
server.oncloseframes in@modelcontextprotocol/server/dist/index.mjs. - The overflow showed up at about 19,000 to 25,000 requests.
Why it happens
Each request saved server.onclose and replaced it with a wrapper that called the previous one. The wrapper was never put back, so the chain grew by one closure per request.
Affected versions
@modelcontextprotocol/server 2.0.0, Node.js 26.5.0, macOS. The report says the chain is not specific to that platform.
Fix steps
0 of 2 done
Your check marks stay in this browser only.
How to check it worked
- After the same request loop,
handler.close()does not throwRangeError: Maximum call stack size exceeded.
If it still fails
- The linked issue does not describe this
RangeErroron2.2.0. On2.0.0the crash followedhandler.close()resolving.
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