MongoDB's flexible document model is powerful but its query syntax — with nested operators, aggregation pipelines, and projection objects — can be hard to recall without documentation open. The MongoDB MCP server lets you ask Claude for your data in plain English and it handles writing the correct query syntax for you. It works with any MongoDB instance: local, Atlas, or Docker.

What is MongoDB?

MongoDB is the world's most popular NoSQL database. Instead of rows and columns, MongoDB stores data as JSON-like documents — flexible, nested structures that map naturally to the objects developers work with in code. A flexible schema means you can evolve your data model without migrations, and documents can hold arrays, nested objects, and mixed field types. MongoDB Atlas is the fully managed cloud version, with automatic scaling, backups, and global replication. The aggregation pipeline is MongoDB's answer to SQL GROUP BY and JOINs — a powerful but syntactically dense way to transform and analyze data across collections.

What the MongoDB MCP Server Does

The MongoDB MCP server connects Claude to your MongoDB instance. Once installed, Claude can query and manipulate your data using natural-language descriptions. The core capabilities include:

  • Query collections with filter conditions — find documents matching any combination of field values, ranges, and operators.
  • Insert and update documents — add new records or update existing ones by describing the changes.
  • Run aggregation pipelines — group, sort, filter, and compute across collections for analytics queries.
  • List databases and collections — explore the structure of your MongoDB instance to understand what data is available.
  • Count documents — quickly count records matching any filter condition.
  • Inspect indexes — see which indexes exist on a collection to understand query performance.

Claude translates your plain-English request into the correct MongoDB query syntax, executes it, and presents the results in a readable format. For related database access patterns, see our Postgres MCP server guide.

Prerequisites

Before installing the MongoDB MCP server, make sure you have the following:

  • MongoDB instance — this can be a local installation, a Docker container running MongoDB, or a MongoDB Atlas cluster. Any version from MongoDB 4.4 onwards should work.
  • Connection URI — for local MongoDB the default is mongodb://localhost:27017. For Atlas, use the connection string from your cluster's Connect dialog, which looks like mongodb+srv://user:password@cluster.mongodb.net/dbname.
  • Node.js 18 or higher — check with node --version. Download from nodejs.org if needed.
  • Claude Desktop — the MCP server connects via Claude Desktop's MCP integration.

How to Install the MongoDB MCP Server

  1. Get your connection URI. For local MongoDB, the URI is typically mongodb://localhost:27017. For Atlas, log into cloud.mongodb.com, select your cluster, click Connect, choose Connect your application, and copy the connection string. Replace <password> with your actual database user password.
  2. Open your Claude Desktop config file. This is claude_desktop_config.json. On macOS it lives at ~/Library/Application Support/Claude/claude_desktop_config.json; on Windows at %APPDATA%\Claude\claude_desktop_config.json. See our full claude_desktop_config.json guide for details.
  3. Add the MongoDB server block using the config JSON below. Paste your connection URI in place of the placeholder.
  4. Save the file and restart Claude Desktop. The MongoDB server will appear in Claude's tool list within a few seconds.

The Config JSON

Add this block to your claude_desktop_config.json. The npx command pulls the latest server version automatically.

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-mongodb"],
      "env": {
        "MONGODB_URI": "mongodb://localhost:27017"
      }
    }
  }
}
Full claude_desktop_config.json entry for the MongoDB MCP server. Replace the URI with your actual MongoDB connection string.

For MongoDB Atlas, replace the MONGODB_URI value with your Atlas connection string:

"MONGODB_URI": "mongodb+srv://user:password@cluster.mongodb.net/dbname"
Atlas connection string format. Substitute your actual username, password, cluster hostname, and database name.

The connection URI contains your database credentials — store it carefully. Read our MCP security and trust levels guide for best practices. Also see our Supabase MCP server guide for a comparison with a Postgres-backed alternative.

Real Use Cases

Once the server is connected, these are the kinds of requests Claude can handle immediately:

  1. "How many users signed up in the last 7 days?" Claude queries the users collection with a createdAt date range filter and returns a count, along with a daily breakdown if you ask for it.
  2. "Find all orders where status is pending and total is greater than $500." Claude constructs the correct MongoDB filter object with $and, $eq, and $gt operators and returns matching documents formatted as a table.
  3. "Show me the 10 most recent documents in the products collection." Claude sorts by _id descending (MongoDB's built-in creation timestamp) and returns the top 10 with all fields.
  4. "Count documents in each status category in the orders collection." Claude builds an aggregation pipeline with $group and $sum to produce a count breakdown by status field.
  5. "Insert a new user document with name, email, and created_at timestamp." Claude constructs and inserts a document with the fields you specify, including setting created_at to the current time.

Pros

  • No MongoDB syntax knowledge required — Claude translates plain English into the correct query operators, projection objects, and aggregation stages, removing the biggest barrier to MongoDB adoption.
  • Works with Atlas and local instances — the same config pattern works for development databases and cloud clusters, making it versatile across environments.
  • Aggregation pipeline support — complex analytics that would require documentation lookups to write manually can be expressed in one sentence to Claude.
  • Composable with other servers — combine MongoDB queries with the Supabase MCP server if you are migrating between backends and need to compare data side by side.

Cons / Limitations

  • Connection URI contains credentials — keep it secure — your MongoDB username and password are embedded in the URI. Never commit your claude_desktop_config.json to a public repository. Use a dedicated low-privilege user for the MCP connection.
  • Write operations need careful prompting — Claude can insert and update documents if you ask it to. Always review what Claude plans to execute before confirming write operations, especially on production data.
  • Complex aggregations may need verification — Claude is generally good at aggregation pipelines, but complex multi-stage pipelines with $lookup, $unwind, and custom expressions should always be verified against expected output before relying on them for business decisions.

Frequently Asked Questions

Yes — just replace the MONGODB_URI value with your Atlas connection string, which looks like mongodb+srv://username:password@cluster.mongodb.net/dbname. Make sure your Atlas cluster's IP access list allows connections from your local machine, or temporarily set it to allow connections from anywhere (0.0.0.0/0) during testing.

Yes. The MongoDB MCP server supports insert, update, and delete operations in addition to reads. This is powerful but risky — always think carefully before asking Claude to modify documents. For analytical and read-only workflows, consider creating a MongoDB user with read-only privileges and using those credentials in the connection URI.

Create a dedicated MongoDB user with the read role (not readWrite) on the relevant database. Use that user's credentials in your MONGODB_URI. This way, even if Claude generates a write query, the database will reject it at the authentication level. In Atlas, go to Database Access and create a user with the Read Only built-in role.

Basic collection queries and aggregation pipelines are well-supported. Full-text search via Atlas Search indexes may be available through the aggregation pipeline's $search stage, depending on the server version. Check the package README for the latest supported operations. For complex Atlas Search queries, you may need to specify the pipeline structure explicitly in your prompt to Claude.