-
Notifications
You must be signed in to change notification settings - Fork 171
Description
Version
mongodb-mcp-server v1.2.0 (installed via pnpm dlx mongodb-mcp-server@latest on 2025-11-10). Source: mongodb-js/mongodb-mcp-server releases.
App
- Cursor
- Windsurf
- VSCode
- VSCode Insiders
- Claude Desktop
- Other
Affected Models (if applicable)
- Claude 3.5 Sonnet
- Claude 3.7 Sonnet
- GPT-4a
- o4-mini
- Other
Bug Description
Summary
Running the official MongoDB MCP server under Node.js v22 crashes shortly after startup with an ESM/CJS interop error. The stack trace shows @mongodb-js/oidc-plugin attempting to require() the ESM-only package openid-client, which throws ERR_REQUIRE_ESM. This prevents the MCP server from running in Cursor IDE and via CLI.
Docs reference for setup pattern used: mongodb-js/mongodb-mcp-server README
Environment
- OS: Windows 11 Pro 10.0.26200
- Node.js: v22.11.0
- pnpm: 9.13.0
- Cursor IDE: latest (2025-11-10)
- MongoDB MCP Server:
mongodb-mcp-server@latest(v1.2.0 as of 2025-10-23) repo @mongodb-js/oidc-plugin: 2.0.5 (from logs)openid-client: 6.8.1 (from logs)- node-gyp: 10.2.0
- Python: 3.12.6
- Visual Studio Build Tools: 2022 Community 17.14.36119.2
Configuration (project-level)
.cursor/mcp.json
{
"mcpServers": {
"MongoDB": {
"command": "pnpm",
"args": ["dlx", "mongodb-mcp-server@latest", "--readOnly=false"],
"env": {
"MDB_MCP_CONNECTION_STRING": "${env:MONGODB_URI}"
}
}
}
}Notes:
- Using env var for connection string follows the README’s guidance (not passing secrets as CLI args) docs.
Reproduction steps
- Ensure
MONGODB_URIis set locally (e.g., in.env.local) and that Cursor/terminal sees it. - Use the above
.cursor/mcp.json. - Start the server via Cursor IDE (MCP stdio) or run from terminal:
pnpm dlx mongodb-mcp-server@latest --readOnly=false
- Within ~10 seconds, the process crashes.
Expected behavior
MCP server should start and remain running; stdio handshake with Cursor should succeed.
Actual behavior
Process exits with ESM/CJS interop error:
Error [ERR_REQUIRE_ESM]: require() of ES Module
[email protected]\node_modules\openid-client\build\index.js
from
...\@[email protected]\node_modules\@mongodb-js\oidc-plugin\dist\plugin.js
not supported.
Instead change the require of index.js in ...\oidc-plugin\dist\plugin.js to a dynamic import()
which is available in all CommonJS modules.
Node.js v22.11.0
Additional context from the same run shows dependency install/compilation is otherwise succeeding; the fatal error is the ERR_REQUIRE_ESM thrown by @mongodb-js/oidc-plugin when loading openid-client.
Impact
- Blocks running MongoDB MCP server on Node 22 (affects Cursor IDE usage and CLI).
- Prevents developers using Node 22 from integrating MongoDB via MCP.
Suspected root cause
@mongodb-js/oidc-plugin (CommonJS build) calls require('openid-client'), but [email protected] is ESM‑only. Under Node 22 this throws ERR_REQUIRE_ESM. The plugin should use dynamic import() or ship an ESM build.
Suggested fixes
- In
@mongodb-js/oidc-plugin:- Replace
require('openid-client')withawait import('openid-client'), or - Provide/ship ESM output and ensure downstreams resolve it correctly.
- Replace
- In
mongodb-mcp-server:- Lazy-load OIDC plugin only when OIDC is configured, or
- Temporarily pin compatible versions in
package.json/lock (if applicable) and declare Node 22 compatibility constraints until the plugin is fixed.