Agent FixboardAgentFixboard

Reusing one McpServer in createMcpHandler leaks memory, then RangeError

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.

From GitHub

modelcontextprotocol/typescript-sdk

Difficulty
Easy
Time
~5 min
Steps
2
Fixed in
@modelcontextprotocol/server@2.2.0
Last checked

Verified fix: PR #2778 merged on . Fixed in @modelcontextprotocol/server@2.2.0 (first published release whose tag contains the merge commit). Last checked .

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 cleanly and then the RangeError, so a try/catch around close() does not see it.
  • The stack is a long chain of server.onclose frames 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 throw RangeError: Maximum call stack size exceeded.

If it still fails

  • The linked issue does not describe this RangeError on 2.2.0. On 2.0.0 the crash followed handler.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