Back to MCP Servers

MongoDB MCP Server

Official MongoDB MCP server with 40+ tools for database operations, Atlas cluster management, stream processing, and performance advisory.

Developer Tools by MongoDB (mongodb-js) Connection String or API Key (Atlas Service Account) active
Overview

The MongoDB MCP Server is the official Model Context Protocol implementation maintained by MongoDB, connecting MongoDB deployments (Atlas, Community Edition, Enterprise Advanced) to MCP-compatible AI agents and IDEs like Cursor, Claude Code, GitHub Copilot in VS Code, and Windsurf. It exposes a comprehensive set of tools for querying and managing databases, administering Atlas clusters, configuring stream processing, and pulling performance advisor recommendations directly from inside an AI agent session.

The server supports two authentication paths: a MongoDB connection string for direct database access (works for both local instances and Atlas clusters) and Atlas API service account credentials for managing organizations, projects, clusters, users, IP access lists, alerts, and stream processing workspaces. It can run as a local stdio process via npx or Docker, or as an HTTP server for shared/team usage. Built-in safety features include a read-only mode, an index-check mode that rejects collection scans, configurable per-query document and byte limits, a disabled-tools allowlist, and a confirmation-required list for destructive operations.

Notable extras include tools for Atlas Local deployments, the MongoDB Assistant knowledge base (search-knowledge and list-knowledge-sources) for grounding agents in official MongoDB documentation, EJSON-formatted exports, and a mcpUI preview feature exposing a web UI. Telemetry is enabled by default but can be disabled via env var.

Tools

Tool Description
find Execute a find query against a collection with optional filters, projection, sort, and limit.
aggregate Run an aggregation pipeline on a collection.
aggregate-db Run an aggregation across an entire database.
count Count documents matching an optional filter.
insert-many Insert multiple documents into a collection.
update-many Update all documents matching a filter.
delete-many Delete all documents matching a filter.
export Export query or aggregation results in EJSON format.
create-collection Create a new collection (auto-creates database if needed).
list-collections List all collections in a database.
rename-collection Rename a collection within a database.
drop-collection Delete a collection and its indexes.
collection-schema Describe a collection's schema structure.
collection-indexes List indexes for a collection.
collection-storage-size Get size metrics for a collection.
create-index Create an index on a collection.
drop-index Remove an index from a collection.
list-databases List all databases on the connection.
db-stats Return usage statistics for a database.
drop-database Delete a database and its data.
connect Establish a MongoDB instance connection.
switch-connection Switch to a different MongoDB connection.
explain Analyze the execution plan for query operations.
mongodb-logs Retrieve recent mongod event logs.
atlas-list-orgs List MongoDB Atlas organizations the credentials can access.
atlas-list-projects List Atlas projects within an organization.
atlas-list-clusters List Atlas clusters in a project.
atlas-inspect-cluster Get metadata and configuration for an Atlas cluster.
atlas-create-free-cluster Provision a free M0 Atlas cluster.
atlas-create-project Create a new Atlas project.
atlas-upgrade-cluster Upgrade a cluster tier (M0 to Flex/M10, Flex to M10).
atlas-create-db-user Create a database user in Atlas.
atlas-list-db-users List database users for a cluster/project.
atlas-create-access-list Authorize an IP or CIDR range to access a cluster.
atlas-inspect-access-list Review authorized IP/CIDR ranges.
atlas-list-alerts Display Atlas alerts for project resources.
atlas-get-performance-advisor Get performance advisor recommendations: suggested indexes, drop-index suggestions, schema suggestions, and a sample of the most recent slow query logs (max 50).
atlas-streams-build Create a stream processing workspace or connection, or deploy a processor.
atlas-streams-discover List and inspect workspaces, connections, and processors.
atlas-streams-manage Start or stop stream processors and modify pipelines.
atlas-streams-teardown Delete stream processing resources.
atlas-local-create-deployment Create a local Atlas deployment (preview image by default).
atlas-local-list-deployments List local Atlas deployments.
atlas-local-connect-deployment Connect to a local Atlas deployment.
atlas-local-delete-deployment Remove a local Atlas deployment.
list-knowledge-sources List available MongoDB documentation/guidance sources.
search-knowledge Search the MongoDB Assistant knowledge base (official docs, curated expert guidance).
Setup Guide

Prerequisites

  • Node.js 20.19.0+, 22.12.0+, or 23+ (or Docker)
  • A MongoDB connection string (for DB tools) and/or Atlas API service account credentials (for Atlas tools)

Install via npx

Run directly with npx (no install needed):

npx -y mongodb-mcp-server@latest --readOnly

Claude Desktop / Cursor / VS Code config

Connection-string based config:

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

Atlas API credentials config (required for Atlas tools):

{
  "mcpServers": {
    "MongoDB": {
      "command": "npx",
      "args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
      "env": {
        "MDB_MCP_API_CLIENT_ID": "your-client-id",
        "MDB_MCP_API_CLIENT_SECRET": "your-client-secret"
      }
    }
  }
}

Docker

{
  "mcpServers": {
    "MongoDB": {
      "command": "docker",
      "args": [
        "run", "--rm", "-i",
        "-e", "MDB_MCP_CONNECTION_STRING",
        "-e", "MDB_MCP_READ_ONLY=true",
        "mongodb/mongodb-mcp-server:latest"
      ],
      "env": {
        "MDB_MCP_CONNECTION_STRING": "mongodb+srv://user:pass@cluster.mongodb.net/db"
      }
    }
  }
}

HTTP transport (shared/team usage)

npx -y mongodb-mcp-server@latest --transport http --httpHost=0.0.0.0 --httpPort=8080

Key configuration env vars

  • MDB_MCP_CONNECTION_STRING: MongoDB URI
  • MDB_MCP_API_CLIENT_ID / MDB_MCP_API_CLIENT_SECRET: Atlas API service account
  • MDB_MCP_READ_ONLY: restrict to read/metadata/connect operations (default false)
  • MDB_MCP_INDEX_CHECK: reject queries that perform collection scans
  • MDB_MCP_DISABLED_TOOLS: comma-separated tool names or categories (atlas, mongodb) to disable
  • MDB_MCP_MAX_DOCUMENTS_PER_QUERY (default 100), MDB_MCP_MAX_BYTES_PER_QUERY (default 16MB)
  • MDB_MCP_TELEMETRY=disabled: opt out of telemetry

Atlas service account permissions

Use the minimum permissions needed: Org Member / Org Read Only / Org Project Creator at org level, and Project Read Only, Cluster Manager, IP Access List Admin, Database Access Admin, or Stream Processing Owner at project level.

Use Cases
  • Let an AI agent explore unfamiliar collections by inspecting schemas, listing indexes, and running sample find and aggregate queries without leaving the IDE.
  • Generate Atlas performance recommendations on demand (suggested indexes, schema improvements, slow query samples) using atlas-get-performance-advisor and act on them via create-index.
  • Bootstrap a new Atlas environment from a prompt: create a project, provision a free cluster, add an IP access list entry, and create a DB user using the atlas-* tools.
  • Build and manage Atlas Stream Processing pipelines (create workspaces, deploy processors, start/stop them) directly from agent conversations.
  • Ground coding assistants in authoritative MongoDB docs via search-knowledge so generated queries and aggregation pipelines match current syntax and best practices.
Example Prompts
  • "Connect to my local MongoDB, show the schema of the orders collection, and list the top 5 customers by order total in the last 30 days."
  • "Run the Atlas performance advisor on the prod-cluster project and create any suggested indexes that touch the events collection."
  • "Provision a free M0 cluster in my dev project on AWS us-east-1, then create a read-only DB user named analytics."
  • "List my Atlas stream processors, stop any that are running on the staging workspace, and delete the ones whose names start with test-."
  • "Search the MongoDB knowledge base for best practices on TTL indexes and then apply one to my sessions collection with a 24-hour expiry."
Pros
  • Officially maintained by MongoDB under the mongodb-js GitHub organization, so coverage tracks Atlas features.
  • Very broad surface area: database CRUD, schema/index management, Atlas org/project/cluster ops, stream processing, performance advisor, and a docs knowledge-base search.
  • Strong safety controls: read-only mode, index-check mode, per-query document/byte caps, disabled-tools list, and confirmation-required list for destructive operations.
  • Multiple deployment modes (stdio via npx, Docker image, HTTP transport) and works with Cursor, Claude Code, VS Code, Windsurf, and other MCP clients.
Limitations
  • Atlas tools require an Atlas service account with appropriate roles; misconfigured permissions silently limit available functionality.
  • HTTP transport is not production-ready out of the box: the docs explicitly require additional TLS, auth, and firewall hardening.
  • Telemetry is enabled by default and must be opted out via MDB_MCP_TELEMETRY=disabled or DO_NOT_TRACK=1.
Alternatives