MongoDB MCP Server: AI Agents for Document Data

⏱️ 3 min read 🔌 MCP Server

What it is: MongoDB's official MCP server (mongodb-mcp-server on npm, maintained in the mongodb-js org). It gives Claude Code, Claude Desktop, or Cursor the ability to list databases and collections, infer collection schemas from sampled documents, run finds and aggregation pipelines, and — for Atlas users — manage clusters through the Atlas Admin API.

Quick answer: Run npx -y mongodb-mcp-server --connectionString "mongodb+srv://…" --readOnly and your agent can explore collections, infer document schemas, and run aggregation pipelines against MongoDB or Atlas. The --readOnly flag blocks all write and delete tools — leave it on for analytics work.

Why it matters for data work

Document databases are where schema lives in code, not the database — which normally makes them painful for ad-hoc analysis. The MCP server closes that gap: the agent samples documents, infers the fields and types actually present, then writes the aggregation pipeline for you. Asking "what's our order volume by week for customers tagged enterprise?" no longer requires remembering nested field paths.

Install & configure

For Claude Code, one command registers it:

claude mcp add mongodb -- npx -y mongodb-mcp-server \
  --connectionString "mongodb+srv://claude_ro:[email protected]/mydb" \
  --readOnly

For Claude Desktop, add to claude_desktop_config.json (Cursor uses the same shape in .cursor/mcp.json):

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": ["-y", "mongodb-mcp-server", "--readOnly"],
      "env": {
        "MDB_MCP_CONNECTION_STRING": "mongodb+srv://claude_ro:[email protected]/mydb"
      }
    }
  }
}

Atlas vs self-hosted: what changes?

Against any reachable MongoDB (local, Docker, self-hosted replica set) the server speaks plain wire protocol via your connection string. With Atlas you can additionally supply an Atlas API client ID/secret, unlocking cluster-management tools (list projects, create clusters, manage access). For pure analytics you don't need the Atlas credentials — the connection string is enough.

How do I keep it safe?

Two layers, same principle as SQL servers: keep --readOnly on so the server never exposes write tools, and connect as a database user whose role is read (or a custom role scoped to specific databases) so writes are impossible even if flags change. Point heavy analytical queries at a secondary member of your replica set to keep load off the primary.

Troubleshooting

Author & links

Author: MongoDB (official)

Repo: github.com/mongodb-js/mongodb-mcp-server

License: Apache-2.0

Related skills

Relational data? Start with the Postgres MCP server or MySQL MCP server. Warehouse-side, see the Snowflake MCP server and BigQuery MCP server. And if you're weighing document vs relational storage, read SQL vs NoSQL.

← Back to MCP Servers