[Bug]: MongoDB MCP Server fails to connect to Claude Code - immediate shutdown after startup
Closed this issue · 3 comments
Bug Description
The MongoDB MCP Server (v0.2.0) fails to connect to Claude Code due to two critical issues that cause immediate server shutdown and connection failures.
Steps to Reproduce
- Configure MongoDB MCP server in Claude Code's
.mcp.json:
{
"mongodb": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://user:pass@cluster.mongodb.net/database?retryWrites=true&w=majority"
}
}
}- Run
claude mcp listto check server connections - Observe that MongoDB server does not appear in connected servers list
Expected Behavior
- MongoDB MCP server should appear as "✓ Connected" in the server list
- Server should remain running and available for MCP operations
Actual Behavior
- Server starts but immediately terminates with "Server close requested" message
- Claude Code health check fails and excludes server from connected list
- Manual testing shows server outputs logging capability warnings then closes
Environment
- Version: 0.2.0
- App: Claude Code (Claude Desktop CLI)
- Node.js: v22.16.0
- OS: Linux 6.14.0-28-generic
- MongoDB: Atlas connection (tested and working independently)
Technical Analysis
Root Causes Identified:
-
Logging Capability Issue (Related to Issue #454):
- Server declares
logging: {}capability insrc/server.tsline ~51 - Does not implement required
logging/setLevelmethod - Causes MCP clients to mark connection as failed
- Server declares
-
Immediate Shutdown Issue:
- Server sends "Server close requested" notification immediately after startup
- Prevents Claude Code from maintaining persistent connection
Evidence
Manual server test shows immediate termination:
$ npx -y mongodb-mcp-server --connectionString "mongodb+srv://..."
[DEBUG] tool: Prevented registration of connect because read-only mode is enabled...
[DEBUG] tool: Prevented registration of create-index because read-only mode is enabled...
# ... more debug messages ...
{"method":"notifications/message","params":{"level":"info","data":"[server]: Server close requested"},"jsonrpc":"2.0"}
{"method":"notifications/message","params":{"level":"debug","data":"[telemetry]: Attempting to send 0 events (0 cached)"},"jsonrpc":"2.0"}The server starts successfully but immediately requests to close, making it impossible for MCP clients to maintain a connection.
Impact
- Complete inability to use MongoDB MCP server with Claude Code
- Affects all Claude Code users trying to integrate MongoDB functionality
- Forces users to seek alternative solutions or third-party implementations
- Makes the official MongoDB MCP server unusable with a major MCP client
Suggested Fix
- Remove logging capability declaration: Remove
logging: {}from theregisterCapabilitiesmethod until proper logging implementation is added - Fix immediate shutdown: Investigate and resolve why server sends close request immediately after startup
- Add proper health check handling: Ensure server responds correctly to MCP client health checks
Workaround
Currently, no workaround exists. The MongoDB connection string works fine with direct MongoDB driver connections, but the MCP server implementation prevents usage through the MCP protocol.
This bug makes the official MongoDB MCP server completely unusable with Claude Code and requires urgent attention.
Thanks for opening this issue. The ticket MCP-161 was created for internal tracking.
Hey, we're working on the logging issue and plan to have a fix in the upcoming weeks. The shutdown log message indicates that we've received an exit signal, such as sigterm or sigabrt and the server is gracefully shutting down because of it. It's not clear why claude code would be issuing that, though.
The corresponding JIRA ticket has been automatically closed.