Menu
Blog Documentation Community Pricing Demo Call Sign Up
Sign Up

How to Set Up a MongoDB MCP Server for Claude, Cursor & Codex

Connect Claude, Cursor, Codex, or any AI agent to your MongoDB database using MCP. Set up the official MongoDB MCP server in minutes.

MCP

This post was written by an engineer at QueryPlane. QueryPlane is an app builder for your database: bring your own postgres db and you can create interactive applications to share with other developers, coworkers or even your customers. If you’re interested in trying it out, get started here.


MCP (Model Context Protocol) lets AI tools like Claude Desktop, Claude Code, Cursor, and Codex connect directly to your MongoDB database. Instead of copy-pasting collection schemas and query results into chat, the AI can inspect your collections, run aggregation pipelines, and analyze your data autonomously.

In this post, we’ll cover:

  • What is MCP — How the protocol works
  • Best MongoDB MCP servers — Official and multi-database options
  • Setup guides — Step-by-step for Claude Desktop and Claude Code
  • Security considerations — Keeping your database safe

What is MCP?

The Model Context Protocol is an open standard created by Anthropic that lets AI applications connect to external data sources and tools. Think of it as a USB-C port for AI — a standardized way for any AI client to talk to any data source.

For databases, MCP servers expose tools that AI agents can call to explore schemas, run queries, and analyze data — without you manually providing context.

Best MongoDB MCP Servers

1. Official MongoDB MCP Server

mongodb-js/mongodb-mcp-server (~1,000 stars) is maintained by MongoDB and is the recommended option.

Features:

  • Full CRUD: find, aggregate, insert-many, update-many, delete-many
  • Atlas Performance Advisor integration (suggested indexes, schema suggestions)
  • Collection and index management
  • Read-only mode available

Claude Desktop config:

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

For read-only mode, add the --readOnly flag to args:

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

2. Google MCP Toolbox for Databases

googleapis/mcp-toolbox (~14,800 stars) supports MongoDB alongside PostgreSQL, MySQL, BigQuery, Snowflake, and more.

Features:

  • Prebuilt generic tools
  • Custom tools framework for domain-specific queries
  • Connection pooling and IAM auth
  • OpenTelemetry observability built in

Best for: Teams already using Google Cloud, or anyone who needs a single MCP server for multiple databases.

See what QueryPlane can build for you

Connect to your database, write SQL with AI, and build shareable apps — all from your browser.

Which MongoDB MCP Server Should You Use?

ServerStarsOfficial?Read-only modeAtlas integration
mongodb-mcp-server~1,000YesYesYes
Google MCP Toolbox~14,800GoogleConfigurableNo

For most developers, use the official MongoDB MCP server — it has the deepest MongoDB integration including Atlas Performance Advisor. If you work with multiple databases, consider Google MCP Toolbox.

Security Considerations

Connecting an AI agent to your MongoDB database carries risk. Follow these practices:

  • Use a read-only database user — create a dedicated user with the read role
  • Enable read-only mode — pass --readOnly to the MCP server
  • Connect to a secondary — point MCP at a secondary replica set member
  • Limit database access — restrict the user to specific databases
  • Don’t expose credentials in configs — use environment variables for connection strings
  • Enable auditing — use MongoDB’s audit log to track queries
// Create a read-only user for MCP
db.createUser({
  user: "mcp_reader",
  pwd: "secure_password",
  roles: [{ role: "read", db: "mydb" }]
});

Using MCP with QueryPlane

If you want the benefits of AI-powered database access without managing MCP servers, QueryPlane provides this out of the box. Connect your MongoDB database and use AI to generate queries, explore schemas, and build dashboards — all from your browser with built-in access controls and team collaboration.

FAQ

What is a MongoDB MCP server?

A MongoDB MCP server is a process that implements the Model Context Protocol to let AI tools (Claude, Cursor, Codex, Windsurf) connect to your MongoDB database. It exposes tools for listing collections, describing schemas, and running queries and aggregations.

How do I connect Claude to MongoDB?

Install the official MongoDB MCP server via npx, then add it to your Claude Desktop config or use claude mcp add in Claude Code. The AI can then query your database directly.

Is it safe to connect AI to my MongoDB database?

It can be safe with proper precautions: use a read-only database user, enable the --readOnly flag, connect to a secondary, and audit queries. Never give an MCP server write access to a production database without careful access controls.

Does MCP work with MongoDB Atlas?

Yes. The official MongoDB MCP server works with MongoDB Atlas and includes Atlas-specific features like Performance Advisor integration for index suggestions and slow query analysis.

Wrapping up

MongoDB has one of the best official MCP integrations in the database ecosystem. The official server supports full CRUD, Atlas integration, and read-only mode out of the box. Start with a read-only setup and see how AI-powered database access fits your workflow.