mongodb-mcp-server fails to start with nvm in Claude, Cursor, or VS Code: how to fix?
I run mongodb-mcp-server via npx in Claude, Cursor, and VS Code on macOS and the server starts then exits immediately, with logs like "Client closed", "No server info found", and for some users
SyntaxError: Unexpected token 'with'. I manage Node with nvm. Why does the MCP server fail to start and what config fixes it?Originally asked on GitHub: https://github.com/mongodb-js/mongodb-mcp-server/issues/192
6 answers
Status: fixed — the issue was closed as completed. The cause in this thread: the MCP client launches a Node version that is too old for the server. A maintainer said the server needs Node >= 20.0.0 (one commenter used >= 20.10.0), so the fix is to make sure the client picks a recent Node/npx.
- Update Node via the official installer. One commenter found
/usr/local/bin/nodewas v18.17.0, installed the Node LTS from https://nodejs.org/en/download (opens external site), and the server then started. - Check which npx the client resolves. Run
where npx. A maintainer suggested setting the MCPcommandto the full npx path, e.g./Users/{user}/.nvm/versions/node/v23.11.0/bin/npx, so the config doesn't depend on your shell environment. - In VS Code, a commenter posted a
.vscode/mcp.jsonthat points directly at the nvm node binary and the installed server:
json{ "servers": { "MongoDB": { "command": "${env:HOME}/.nvm/versions/node/v20.16.0/bin/node", "args": ["/usr/local/lib/node_modules/mongodb-mcp-server/dist/index.js"], "env": { "MDB_MCP_CONNECTION_STRING": "YOUR_MONGODB_CONNECTION_STRING", "NODE_OPTIONS": "--experimental-json-modules --no-warnings" } } } }Replace
v20.16.0with your nvm version; if installed locally, use${workspaceFolder}/node_modules/mongodb-mcp-server/dist/index.js. 4. Maintainer workaround:npm install --global mongodb-mcp-serverand set"command": "mongodb-mcp-server"directly. Updating is then manual, so npx is preferred.A Cursor user also had a failing config with
env.PATHset to/opt/homebrew/bin/npx; the maintainer said npx usually isn't installed via Homebrew and that PATH shouldn't need to be overridden. General advice: connection strings contain credentials and are stored in plaintext in these config files, so don't commit them.Did this work for you?- Update Node via the official installer. One commenter found
What @shyambh tried on GitHub (Worked)
A commenter found
/usr/local/bin/nodewas v18.17.0, downloaded the Node LTS installer from nodejs.org, and confirmed the MCP server then started because the installer updated the Node used by the client.Did this work for you?What @gagik tried on GitHub (Outcome unclear)
The maintainer suggested running
where npxand setting the MCPcommandto the full path of the preferred npx binary (e.g./Users/{user}/.nvm/versions/node/v23.11.0/bin/npx) so the config does not depend on the shell environment.Did this work for you?What @emmanuelByte tried on GitHub (Outcome unclear)
A commenter posted a VS Code
.vscode/mcp.jsonfix:commandset to${env:HOME}/.nvm/versions/node/v20.16.0/bin/node,argspointing at the global serverdist/index.js, andNODE_OPTIONS=--experimental-json-modules --no-warningsto address thewithsyntax error.Did this work for you?What a GitHub user tried on GitHub (Didn't work)
The reporter tried the advice from the mongodb-mcp-server repository without success. Co-workers had gotten it working by adding an
env.PATHpointing at the nvm node bin directory (e.g./Users/<xxx>/.nvm/versions/node/v22.15.0/bin:/bin) to the MCP config, but the reporter did not confirm trying that specific change.Source: https://github.com/mongodb-js/mongodb-mcp-server/issues/192 (opens external site)
Did this work for you?What @shashank-yelluri tried on GitHub (Didn't work)
A commenter using Cursor set
env.PATHto/opt/homebrew/bin/npxin the MCP config; the logs show the process starting then closing withClient closedandNo server info found.Did this work for you?
Related questions
- mongodb-mcp-server count tool ignores filter and returns total collection count in Cursor
- mongodb-mcp-server Docker container doesn't exit — fixed in v0.1.2?
- mongodb-mcp-server in Docker: can't connect via HTTP to localhost:9091 — what transport does it use?
- How do I export MongoDB query results to JSON in mongodb-mcp-server?
- Can mongodb-mcp-server be hosted as a remote MCP server over HTTP?