MCP.so
Sign In

MongoDB MCP Server

@mongodb-js

About MongoDB MCP Server

A Model Context Protocol server to connect to MongoDB databases and MongoDB Atlas Clusters.

Config

Add this server to your MCP-compatible client using the configuration below.

{
  "mcpServers": {
    "MongoDB": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server"
      ],
      "env": {
        "MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase"
      }
    }
  }
}

Tools

27

Run an aggregation against a MongoDB database

Run an aggregation against a MongoDB collection

Describe the indexes for a collection

Describe the schema for a collection

Gets the size of the collection

Connect to a MongoDB instance and get back a connectionId to pass to the other MongoDB tools. Each call establishes a new, independent connection — multiple connections can be active at the same time. A connection with the id "preconfigured" already exists for the connection string the server was configured with — there is no need to call this tool to use it.

Gets the number of documents in a MongoDB collection using db.collection.count() and query as an optional filter parameter

Creates a new collection in a database. If the database doesn't exist, it will be created automatically.

Create an index for a collection

Returns statistics that reflect the use state of a single database

Removes all documents that match the filter from a MongoDB collection

Close a MongoDB connection and revoke its connectionId. Disconnecting the "preconfigured" connection only closes it — it reconnects automatically on next use because the server configuration still declares it.

Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection.

Removes the specified database, deleting the associated data files

Drop an index for the provided database and collection.

Returns statistics describing the execution of the winning plan chosen by the query optimizer for the evaluated method

Export a query or aggregation results in the specified EJSON format.

Run a find query against a MongoDB collection

Insert an array of documents into a MongoDB collection. If the list of documents is above com.mongodb/maxRequestPayloadBytes, consider inserting them in batches.

List all collections for a given database

List the active MongoDB connections and their connectionIds. Use this to discover the "preconfigured" connection or to find a connectionId established earlier.

List all databases for a MongoDB connection

Returns the most recent logged mongod events

Renames a collection in a MongoDB database

Updates all documents that match the specified filter for a collection. If the list of documents is above com.mongodb/maxRequestPayloadBytes, consider updating them in batches.

List available data sources in the MongoDB Assistant knowledge base. Use this to explore available data sources or to find search filter parameters to use in search-knowledge.

Search for information in the MongoDB Assistant knowledge base. This includes official documentation, curated expert guidance, and other resources provided by MongoDB. Supports filtering by data source and version.

Overview

What is MongoDB MCP Server?

It is a Model Context Protocol server for interacting with MongoDB databases and MongoDB Atlas. It allows AI assistants to perform read‑only (or optionally write) database operations and manage Atlas resources using either a MongoDB connection string or Atlas API service account credentials.

How to use MongoDB MCP Server?

Requires Node.js v22.13 or later. Configure it in your MCP client (e.g., VS Code, Cursor, Claude Desktop) by running npx -y mongodb-mcp-server@latest with the --readOnly flag by default. Pass credentials via environment variables (MDB_MCP_CONNECTION_STRING or MDB_MCP_API_CLIENT_ID/MDB_MCP_API_CLIENT_SECRET). Docker images are also available.

Key features of MongoDB MCP Server

  • Supports MongoDB Atlas tools (API‑based) and database tools (driver‑based).
  • Provides MongoDB assistant tools for common help tasks.
  • Reads database schemas, collections, and indexes as resources.
  • Configurable via environment variables, command‑line arguments, or MCP client configuration.
  • Runs as a standalone service or inside a Docker container.
  • Defaults to read‑only mode; remove --readOnly to enable writes.

Use cases of MongoDB MCP Server

  • Query and explore MongoDB databases through a conversational AI assistant.
  • Manage Atlas clusters, projects, and API keys using service account credentials.
  • Retrieve database schemas and indexes for documentation or migration planning.
  • Deploy as a microservice on public clouds such as Azure.

FAQ from MongoDB MCP Server

What are the prerequisites to run MongoDB MCP Server?

Node.js v22.13 or later is required. A MongoDB connection string or Atlas API service account credentials must be provided.

Is the server read‑only by default?

Yes. All configuration examples include the --readOnly flag. Remove it if you need write operations.

Can I run MongoDB MCP Server using Docker?

Yes. A Docker image mongodb/mongodb-mcp-server:latest is available. Pass environment variables via -e flags or through an MCP configuration file.

How do I pass credentials securely?

The README strongly recommends using environment variables (MDB_MCP_CONNECTION_STRING, MDB_MCP_API_CLIENT_ID, MDB_MCP_API_CLIENT_SECRET) instead of command‑line arguments to avoid exposing secrets in process lists or logs.

Which MCP clients are supported?

Configuration examples are provided for Windsurf, VS Code, Claude Desktop, Cursor, Copilot CLI, and Opencode CLI.

Frequently asked questions

What are the prerequisites to run MongoDB MCP Server?

Node.js v22.13 or later is required. A MongoDB connection string or Atlas API service account credentials must be provided.

Is the server read‑only by default?

Yes. All configuration examples include the `--readOnly` flag. Remove it if you need write operations.

Can I run MongoDB MCP Server using Docker?

Yes. A Docker image `mongodb/mongodb-mcp-server:latest` is available. Pass environment variables via `-e` flags or through an MCP configuration file.

How do I pass credentials securely?

The README strongly recommends using environment variables (`MDB_MCP_CONNECTION_STRING`, `MDB_MCP_API_CLIENT_ID`, `MDB_MCP_API_CLIENT_SECRET`) instead of command‑line arguments to avoid exposing secrets in process lists or logs.

Which MCP clients are supported?

Configuration examples are provided for Windsurf, VS Code, Claude Desktop, Cursor, Copilot CLI, and Opencode CLI.

Comments

More Databases MCP servers