Skip to main content
Guide1 min read

MongoDB MCP server: setup for Claude & Cursor (2026)

Connect MongoDB or Atlas to your AI client with the official MongoDB MCP server. Connection string, read-only mode, config, and common fixes.

The MongoDB MCP server — maintained by MongoDB itself — lets an AI client inspect collections, run queries and explore your schema, against a local instance or an Atlas cluster. Here is the safe setup for Claude Desktop and Cursor.

Configure the client

Pass the connection string via an environment variable (never as a CLI arg, where it can leak into process lists) and start in read-only mode:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
      "env": {
        "MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
      }
    }
  }
}

For Atlas, use the full mongodb+srv://user:pass@cluster.mongodb.net/db string with a valid database user. Restart the client; see MCP config file location if you cannot find the file.

Why --readOnly

The flag restricts the server to non-destructive operations — the AI can query and analyse but cannot insert, update or drop. Keep it on unless you explicitly need writes, and never run write-enabled against production. This is the least-privilege principle from our MCP security best practices.

Verify

Ask: "List the collections in my database and show a sample document from users." Real data back means you are connected.

Common problems

  • Authentication failed — wrong user/password in the connection string, or the user lacks access to that database.
  • connection timed out — for Atlas, your IP is not in the network access allowlist; add it in the Atlas dashboard.
  • Write attempts rejected — that is --readOnly; remove it only when needed.
  • No tools in client — Node 18+ required; see Cursor MCP not working.

Going further

MongoDB fits a backend stack with GitHub and filesystem servers — see the best MCP stack for a backend developer and the databases category. Comparing engines? Read best MCP server for a database.

Loadout

Build your AI agent loadout

The directory of MCP servers and AI agents that actually work. Pick the right loadout for Slack, Postgres, GitHub, Figma and 20+ integrations — with install commands ready to paste into Claude Desktop, Cursor or your own stack.

© 2026 Loadout. Built on Angular 21 SSR.