mongodb-js/mongodb-mcp-server

JavaScript heap out of memory

Closed this issue · 6 comments

v0.1.2

npx -y mongodb-mcp-server --connectionString mongodb://

<--- Last few GCs --->

[28:0x7f1a3c365650] 117783 ms: Mark-Compact 4043.9 (4130.9) -> 4036.9 (4140.2) MB, 3333.51 / 0.00 ms (average mu = 0.850, current mu = 0.104) allocation failure; scavenge might not succeed
[28:0x7f1a3c365650] 122334 ms: Mark-Compact 4052.7 (4140.2) -> 4044.5 (4147.4) MB, 4518.03 / 0.00 ms (average mu = 0.668, current mu = 0.007) allocation failure; scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

Hi @bootgo ,

can you please provide more information of what you were doing, along with your OS and Node.js version? Did you manage to connect to the server using an application like Claude or VSCode?

Here's a concise summary of the encountered issues

1‌. Environment‌:

Running MongoDB MCP Server via supergateway:latest (Alpine Linux 3.22) with Node.js v20.19.2.
Command:
supergateway --stdio "npx -y mongodb-mcp-server --connectionString..." --port 8000 --ssePath /sse --messagePath /message

2‌. Memory Error‌:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory during operations.

  1. MCP-Inspector Behavior‌:

‌v0.1.1‌: All requests delayed by 10s (e.g., list-databases).
‌v0.1.2‌: First request (e.g., list-databases) succeeds instantly, but subsequent requests (even after switching tools,such as list-collections) fail, then i got the heap memory error.

If you skip using supergateway and use the server through stdio, do you still see the heap allocation issue?

We can't ensure that the mcp server works in any other transport, at least for now, while we are developing support for the http transport.

I am also experiencing what appears to be a memory leak with version 0.1.2.

I am using Windows 11 Enterprise v10.0.26100 with vscode v1.101.2 and node v22.17.0.
I start the MCP server using "npx -y mongodb-mcp-server".

Via Task Manager, when I start the server, I see two Node.js JavaScript Runtime proceses start and use about 30-40 MB of memory each.

When I connect to my mongodb instance, one of the Node.js processes starts a steady increase of memory usage until it hits 4000+ MB after a few seconds. After a few more seconds of it bouncing around the 4000 MB range, the processes close and the output logs show the following.

2025-06-27 11:26:05.616 [warning] [server stderr]
2025-06-27 11:26:05.616 [warning] [server stderr] <--- Last few GCs --->
2025-06-27 11:26:05.617 [warning] [server stderr]
2025-06-27 11:26:05.618 [warning] [server stderr] [4620:00000295751A1000] 68002 ms: Mark-Compact 4040.5 (4128.3) -> 4035.2 (4138.6) MB, pooled: 0 MB, 2117.51 / 0.00 ms (average mu = 0.517, current mu = 0.245) allocation failure; scavenge might not succeed
2025-06-27 11:26:05.618 [warning] [server stderr] [4620:00000295751A1000] 72405 ms: Mark-Compact 4051.0 (4138.6) -> 4042.5 (4145.8) MB, pooled: 0 MB, 4327.61 / 0.00 ms (average mu = 0.253, current mu = 0.017) allocation failure; scavenge might not succeed
2025-06-27 11:26:05.619 [warning] [server stderr]
2025-06-27 11:26:05.619 [warning] [server stderr]
2025-06-27 11:26:05.620 [warning] [server stderr] <--- JS stacktrace --->
2025-06-27 11:26:05.620 [warning] [server stderr]
2025-06-27 11:26:05.620 [warning] [server stderr] FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
2025-06-27 11:26:05.621 [warning] [server stderr] ----- Native stack trace -----
2025-06-27 11:26:05.621 [warning] [server stderr]
2025-06-27 11:26:05.667 [warning] [server stderr] 1: 00007FF65C59542D node::SetCppgcReference+17693
2025-06-27 11:26:05.668 [warning] [server stderr] 2: 00007FF65C4F8248 SSL_get_quiet_shutdown+102712
2025-06-27 11:26:05.675 [warning] [server stderr] 3: 00007FF65D07ED41 v8::Isolate::ReportExternalAllocationLimitReached+65
2025-06-27 11:26:05.676 [warning] [server stderr] 4: 00007FF65D06B9C6 v8::Function::Experimental_IsNopFunction+2870
2025-06-27 11:26:05.677 [warning] [server stderr] 5: 00007FF65CEB8B10 v8::internal::StrongRootAllocatorBase::StrongRootAllocatorBase+31456
2025-06-27 11:26:05.678 [warning] [server stderr] 6: 00007FF65CEB5B7A v8::internal::StrongRootAllocatorBase::StrongRootAllocatorBase+19274
2025-06-27 11:26:05.678 [warning] [server stderr] 7: 00007FF65CECB3D1 v8::Isolate::GetHeapProfiler+7793
2025-06-27 11:26:05.679 [warning] [server stderr] 8: 00007FF65CECBC78 v8::Isolate::GetHeapProfiler+10008
2025-06-27 11:26:05.680 [warning] [server stderr] 9: 00007FF65CEDC92B v8::Isolate::GetHeapProfiler+78795
2025-06-27 11:26:05.680 [warning] [server stderr] 10: 00007FF65CBA5A1B v8::base::AddressSpaceReservation::AddressSpaceReservation+322075
2025-06-27 11:26:05.681 [warning] [server stderr] 11: 00007FF5FD0ED4BA
2025-06-27 11:26:06.059 [info] Connection state: Error Process exited with code 134

I have reverted back to v0.1.1 using the start command "npx -y mongodb-mcp-server@v0.1.1" and it is working as expected.

Hey @mikepedeupe ,

thanks for sharing more information. We have been investigating the issue and might be related to some recent changes on our internal telemetry.

Can you try 0.0.12 with either:

  • An env var MDB_MCP_TELEMETRY=disabled
  • A cli flag: --telemetry disabled

It should unblock you so you can use the latest features and fixes.

Hi @kmruiz ,

I can confirm that adding the env var resolved the issue.

I tried the original setup first without specifying the version and confirmed it still failed. I then added:

"MDB_MCP_TELEMETRY": "disabled"

to my "env" section of the vscode MCP config section for the server.

After restart, it is able to iteract with the mongodb server as expected with no noticable memory increase.

Thanks!