Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: MongoDB MCP Server fails to connect to Claude Code - immediate shutdown after startup #485

Closed
Assignees
@pranav-iihglobal

Description

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

  1. 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"
 }
 }
}
  1. Run claude mcp list to check server connections
  2. 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:

  1. Logging Capability Issue (Related to Issue [Bug]: Incorrect logging capability declaration causing connection errors in MCP Inspector #454 ):

    • Server declares logging: {} capability in src/server.ts line ~51
    • Does not implement required logging/setLevel method
    • Causes MCP clients to mark connection as failed
  2. 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

  1. Remove logging capability declaration: Remove logging: {} from the registerCapabilities method until proper logging implementation is added
  2. Fix immediate shutdown: Investigate and resolve why server sends close request immediately after startup
  3. 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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /