MongoDB MCP Server

MongoDB MCP servers enable AI models to interact with MongoDB databases and MongoDB Atlas, providing capabilities for document operations, aggregation pipelines, cloud database management, and natural language queries.

GitHub starsnpm version

Overview

The MongoDB MCP Server is the official Model Context Protocol server from MongoDB that enables AI assistants to interact directly with MongoDB databases and MongoDB Atlas. It provides natural language access to database operations, schema inspection, and cloud resource management for both local and Atlas deployments.

Official Server:

Developed and maintained by MongoDB

Key Features

🍃

MongoDB Atlas Integration

Manage Atlas clusters, projects, users, and network access directly through AI

📄

Document Operations

Query, insert, update, and delete documents using natural language commands

🔍

Schema Intelligence

Automatic schema inspection and pattern discovery across collections

🔐

Read-Only Mode

Built-in read-only mode for safe data exploration and analysis

Available Tools

Quick Reference

ToolPurposeCategory
connectConnect to MongoDB instanceConnection
findQuery documents in collectionRead
aggregateRun aggregation pipelinesRead
countCount documents in collectionRead
insert-oneInsert single documentWrite
insert-manyInsert multiple documentsWrite
update-oneUpdate single documentWrite
update-manyUpdate multiple documentsWrite
delete-oneDelete single documentWrite
delete-manyDelete multiple documentsWrite
create-indexCreate collection indexSchema
list-databasesList all databasesSchema
list-collectionsList collections in databaseSchema
collection-schemaDescribe collection schemaSchema
collection-indexesList collection indexesSchema
collection-storage-sizeGet collection size in MBStats
db-statsGet database statisticsStats
rename-collectionRename a collectionAdmin
drop-collectionRemove a collectionAdmin
drop-databaseRemove a databaseAdmin

Detailed Usage

connect

Establish connection to a MongoDB instance using a connection string.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "connect",
  arguments: {
    connectionString: "mongodb://localhost:27017/myDatabase"
  }
});

Supports MongoDB Atlas, Community Edition, and Enterprise Advanced.

find

Query documents from a collection with optional filters and projections.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "find",
  arguments: {
    database: "myDatabase",
    collection: "users",
    filter: { status: "active" },
    limit: 10
  }
});
aggregate

Execute aggregation pipelines for complex data transformations and analytics.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "aggregate",
  arguments: {
    database: "myDatabase",
    collection: "orders",
    pipeline: [
      { $match: { status: "completed" } },
      { $group: { _id: "$customerId", total: { $sum: "$amount" } } },
      { $sort: { total: -1 } }
    ]
  }
});
count

Count documents in a collection matching optional filter criteria.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "count",
  arguments: {
    database: "myDatabase",
    collection: "users",
    filter: { status: "active" }
  }
});
insert-one

Insert a single document into a collection.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "insert-one",
  arguments: {
    database: "myDatabase",
    collection: "users",
    document: {
      name: "John Doe",
      email: "[email protected]",
      status: "active"
    }
  }
});

Disabled when using --readOnly flag.

insert-many

Insert multiple documents into a collection in a single operation.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "insert-many",
  arguments: {
    database: "myDatabase",
    collection: "users",
    documents: [
      { name: "Alice", email: "[email protected]" },
      { name: "Bob", email: "[email protected]" }
    ]
  }
});
update-one

Update a single document matching the filter criteria.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "update-one",
  arguments: {
    database: "myDatabase",
    collection: "users",
    filter: { email: "[email protected]" },
    update: { $set: { status: "inactive" } }
  }
});
create-index

Create an index on a collection to improve query performance.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "create-index",
  arguments: {
    database: "myDatabase",
    collection: "users",
    keys: { email: 1 },
    options: { unique: true }
  }
});
list-databases

List all databases accessible through the current connection.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "list-databases",
  arguments: {}
});
list-collections

List all collections in a specified database.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "list-collections",
  arguments: {
    database: "myDatabase"
  }
});
collection-schema

Inspect the schema structure of a collection by analyzing document samples.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "collection-schema",
  arguments: {
    database: "myDatabase",
    collection: "users"
  }
});

Useful for understanding data patterns and field types in schema-less documents.

collection-indexes

List all indexes defined on a collection.

use_mcp_tool({
  server_name: "mongodb",
  tool_name: "collection-indexes",
  arguments: {
    database: "myDatabase",
    collection: "users"
  }
});

MongoDB Atlas Tools

The server also provides tools for managing MongoDB Atlas resources:

  • Organization & Project Management: List and create Atlas organizations and projects
  • Cluster Operations: Create free tier clusters, list clusters across projects
  • User Management: Create database users with specific roles
  • Network Security: Manage IP access lists
  • Monitoring: Access alerts and performance advisories
  • Atlas Local: Deploy and manage local Atlas development environments

Installation

Prerequisites

  • Node.js 20.19.0+, v22.12.0+, or v23+
  • MongoDB connection string (local or Atlas)

Configuration

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

Read-Only Mode:

The --readOnly flag is recommended for safe data exploration. Remove it to enable write operations.

Atlas Connection String Example

{
  "env": {
    "MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase"
  }
}

Common Use Cases

Data Analysis

Explore data patterns and schemas using natural language:

"Show me the schema of the users collection and find the most common user types"

Query Generation

Generate complex aggregation pipelines:

"Create an aggregation to group orders by customer and calculate total spending,
sorted by highest spenders first"

Database Administration

Manage indexes and performance:

"Create a unique index on the email field in the users collection,
then show all indexes for that collection"

Additional Deployment Options

Docker

Run the server in a container without local Node.js:

docker run -e MDB_MCP_CONNECTION_STRING="mongodb://..." mongodb-mcp-server

HTTP Server

Deploy as an HTTP service:

npx mongodb-mcp-server --transport http --port 3000

HTTP Security:

When using HTTP transport, implement authentication, TLS encryption, and firewall protection. Never expose directly to the internet.

Sources