MongoDB MCP Server

by mongodb-js

1.1k 445.4k downloads Not rated yet MIT

About

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

Details

License
MIT

Explore

- 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.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MongoDB MCP Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Prerequisites

> [!NOTE]
> Node 20.x support is deprecated and will be removed in a future release. Please upgrade to Node 22.13 or later. See https://nodejs.org/en/blog/migrations/v20-to-v22 for migration details.

- Node.js
- At least v22.13.0. Check with node -v.

- A MongoDB connection string or Atlas API credentials.
- _Service Accounts Atlas API credentials_ are required to use the Atlas tools. You can create a service account in MongoDB Atlas and use its credentials for authentication. See Atlas API Access for more details.
- If you have a MongoDB connection string, you can use it directly to connect to your MongoDB instance.

Quick Start

> 🔒 Security Recommendation 1: When using Atlas API credentials, be sure to assign only the minimum required permissions to your service account. See Atlas API Permissions for details.

> 🔒 Security Recommendation 2: For enhanced security, we strongly recommend using environment variables to pass sensitive configuration such as connection strings and API credentials instead of command line arguments. Command line arguments can be visible in process lists and logged in various system locations, potentially exposing your secrets. Environment variables provide a more secure way to handle sensitive information.

Most MCP clients require a configuration file to be created or modified to add the MCP server.

Note: The configuration file syntax can be different across clients. Please refer to the following links for the latest expected syntax:

- Windsurf: https://docs.windsurf.com/windsurf/mcp
- VSCode: https://code.visualstudio.com/docs/copilot/chat/mcp-servers
- Claude Desktop: https://modelcontextprotocol.io/quickstart/user
- Cursor: https://docs.cursor.com/context/model-context-protocol
- Copilot CLI: https://docs.github.com/en/copilot/concepts/agents/about-copilot-cli
- Opencode CLI: https://opencode.ai/docs/mcp-servers

> Default Safety Notice: All examples below include --readOnly by default to ensure safe, read-only access to your data. Remove --readOnly if you need to enable write operations.

Option 3: Standalone Service using environment variables and command line arguments

You can source environment variables defined in a config file or explicitly set them like we do in the example below and run the server via npx.

```shell

aggregate-db

Run an aggregation against a MongoDB database

aggregate

Run an aggregation against a MongoDB collection

collection-indexes

Describe the indexes for a collection

collection-schema

Describe the schema for a collection

collection-storage-size

Gets the size of the collection

connect

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.

count

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

create-collection

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

create-index

Create an index for a collection

db-stats

Returns statistics that reflect the use state of a single database

delete-many

Removes all documents that match the filter from a MongoDB collection

disconnect

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.

drop-collection

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

drop-database

Removes the specified database, deleting the associated data files

drop-index

Drop an index for the provided database and collection.

explain

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

export

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

find

Run a find query against a MongoDB collection

insert-many

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-collections

List all collections for a given database

list-connections

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

list-databases

List all databases for a MongoDB connection

mongodb-logs

Returns the most recent logged mongod events

rename-collection

Renames a collection in a MongoDB database

update-many

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-knowledge-sources

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-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.

- aggregate - Run an aggregation against a MongoDB collection
- aggregate-db - Run an aggregation against a MongoDB database
- collection-indexes - Describe the indexes for a collection
- collection-schema - Describe the schema for a collection
- collection-storage-size - Gets the size of the collection
- connect - Connect to a MongoDB instance
- count - Gets the number of documents in a MongoDB collection using db.collection.count() and query as an optional filter parameter
- create-collection - Creates a new collection in a database. If the database doesn't exist, it will be created automatically.
- create-index - Create an index for a collection
- db-stats - Returns statistics that reflect the use state of a single database
- delete-many - Removes all documents that match the filter from a MongoDB collection
- drop-collection - Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection.
- drop-database - Removes the specified database, deleting the associated data files
- drop-index - Drop an index for the provided database and collection.
- explain - Returns statistics describing the execution of the winning plan chosen by the query optimizer for the evaluated method
- export - Export a query or aggregation results in the specified EJSON format.
- find - Run a find query against a MongoDB collection
- insert-many - 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-collections - List all collections for a given database
- list-databases - List all databases for a MongoDB connection
- mongodb-logs - Returns the most recent logged mongod events
- rename-collection - Renames a collection in a MongoDB database
- switch-connection - Switch to a different MongoDB connection
- update-many - 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.

- atlas-connect-cluster - Connect to MongoDB Atlas cluster
- atlas-create-access-list - Allow Ip/CIDR ranges to access your MongoDB Atlas clusters.
- atlas-create-cluster - Create a MongoDB Atlas cluster (M10–M80, replica set or single shard). Compute autoscaling is enabled by default: min instance size is set to the selected instance size, max is set two tiers above. Disk autoscaling is always enabled. The tool returns immediately, use the atlas-inspect-cluster tool to poll the cluster state for readiness (state: IDLE). Connection strings are unavailable until the cluster reaches IDLE state.
- atlas-create-db-user - Create an MongoDB Atlas database user
- atlas-create-free-cluster - Create a free MongoDB Atlas cluster
- atlas-create-project - Create a MongoDB Atlas project
- atlas-get-performance-advisor - Get MongoDB Atlas performance advisor recommendations and suggestions, which includes the operations: suggested indexes, drop index suggestions, schema suggestions, and a sample of the most recent (max 50) slow query logs
- atlas-inspect-access-list - Inspect Ip/CIDR ranges with access to your MongoDB Atlas clusters.
- atlas-inspect-cluster - Inspect metadata of a MongoDB Atlas cluster
- atlas-list-alerts - List triggered alerts for a MongoDB Atlas project. These are alerts Atlas has raised, not the alert configurations that define them. Defaults to OPEN alerts; set status to TRACKING or CLOSED to see others.
- atlas-list-clusters - List MongoDB Atlas clusters
- atlas-list-db-users - List MongoDB Atlas database users
- atlas-list-orgs - List MongoDB Atlas organizations
- atlas-list-projects - List MongoDB Atlas projects
- atlas-load-sample-dataset - Load a MongoDB sample dataset into an Atlas cluster, or check the status of a previously-initiated load. To start a new load, provide clusterName — the load runs asynchronously and the response includes a jobId and initial state. To check progress, call this tool again with jobId (sample dataset loads typically take 1–5 minutes). State can be WORKING, COMPLETED, or FAILED.
- atlas-pause-resume-cluster - Pause or resume a dedicated (M10+) MongoDB Atlas cluster.
- atlas-streams-build - Create Atlas Stream Processing resources. Use this tool for 'set up a Kafka pipeline', 'create a workspace', 'add a connection', or 'deploy a processor'. Use resource='workspace' to create a new workspace (specify cloud provider, region, and tier). Use resource='connection' to add a data source or sink to an existing workspace. Use resource='processor' to deploy a stream processor with a pipeline. Use resource='privatelink' to set up private networking. Typical workflow: create workspace → add connections → deploy processor.
- atlas-streams-discover - Discover and inspect Atlas Stream Processing resources. Also use for 'why is my processor failing', 'what workspaces do I have', 'show processor stats', or 'check processor health'. Use 'list-workspaces' to see all workspaces in a project. Use inspect actions for details on a specific resource. Use 'diagnose-processor' for a combined health report including state, stats, connection health, and recent errors. Use 'get-networking' for PrivateLink and account details.
- atlas-streams-manage - Manage Atlas Stream Processing resources: start/stop processors, modify pipelines, update configurations. Also use for 'change the pipeline', 'scale up my processor', or 'update my workspace tier'. Common workflow: action='stop-processor' → action='modify-processor' → action='start-processor'. Use atlas-streams-discover with action 'inspect-processor' to check state before managing.
- atlas-streams-teardown - Delete Atlas Stream Processing resources. Also use for 'remove my workspace', 'disconnect a source', 'delete all processors', or 'clean up my streams environment'. Performs basic safety checks before deletion: summarizes counts of processors and connections, highlights connections referenced by processors where possible, and surfaces API errors if processors are still running when deletion is attempted. Use atlas-streams-discover to review resources before deleting.
- atlas-upgrade-cluster - Upgrade a MongoDB Atlas cluster tier. Upgrades Free (M0) clusters to Flex or M10 Dedicated, or Flex clusters to M10 Dedicated. The upgrade path is determined automatically from the current tier unless overridden with targetTier. Note to LLM: If provider and region are not already known, ask for both together in a single question before calling this tool. Common region mappings by provider (default recommendation: AWS US_EAST_1):
AWS: "East Coast"/"Virginia"/"US East" → US_EAST_1, "Ohio" → US_EAST_2, "California"/"West Coast" → US_WEST_2, "Southeast Asia"/"APAC"/"Singapore" → AP_SOUTHEAST_1, "Europe"/"EU"/"Ireland" → EU_WEST_1.
GCP: "Central US" → CENTRAL_US, "Western US" → WESTERN_US, "Southeast Asia"/"APAC" → SOUTHEASTERN_ASIA_PACIFIC, "Europe"/"EU" → WESTERN_EUROPE.
AZURE: "East US" → US_EAST_2, "West US" → US_WEST_2, "Europe"/"EU" → EUROPE_NORTH.

NOTE: atlas tools are only available when you set credentials on configuration section.

- atlas-local-connect-deployment - Connect to a MongoDB Atlas Local deployment
- atlas-local-create-deployment - Create a MongoDB Atlas local deployment. Default image is preview. When the user does not specify an image tag, inform them that preview is used by default and provide this link for more information: https://hub.docker.com/r/mongodb/mongodb-atlas-local
- atlas-local-delete-deployment - Delete a MongoDB Atlas local deployment
- atlas-local-list-deployments - List MongoDB Atlas local deployments

- list-knowledge-sources - 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-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.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

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

McpServers

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

A Model Context Protocol server for interacting with MongoDB Databases and MongoDB Atlas.

📚 Table of Contents

- 🚀 Getting Started
- Prerequisites
- Setup
- Quick Start
- 🛠️ Supported Tools
- MongoDB Atlas Tools
- MongoDB Database Tools
- MongoDB Assistant Tools
- 📄 Supported Resources
- ⚙️ Configuration
- Configuration Options
- Atlas API Access
- Configuration Methods
- Environment Variables
- Command-Line Arguments
- MCP Client Configuration
- Proxy Support
- 🚀 Deploy on Public Clouds
- Azure Cloud
- 🤝 Contributing

<a name="getting-started"></a>

Prerequisites

> [!NOTE]
> Node 20.x support is deprecated and will be removed in a future release. Please upgrade to Node 22.13 or later. See https://nodejs.org/en/blog/migrations/v20-to-v22 for migration details.

- Node.js
- At least v22.13.0. Check with node -v.

- A MongoDB connection string or Atlas API credentials.
- _Service Accounts Atlas API credentials_ are required to use the Atlas tools. You can create a service account in MongoDB Atlas and use its credentials for authentication. See Atlas API Access for more details.
- If you have a MongoDB connection string, you can use it directly to connect to your MongoDB instance.

Setup

Quick Start

> 🔒 Security Recommendation 1: When using Atlas API credentials, be sure to assign only the minimum required permissions to your service account. See Atlas API Permissions for details.

> 🔒 Security Recommendation 2: For enhanced security, we strongly recommend using environment variables to pass sensitive configuration such as connection strings and API credentials instead of command line arguments. Command line arguments can be visible in process lists and logged in various system locations, potentially exposing your secrets. Environment variables provide a more secure way to handle sensitive information.

Most MCP clients require a configuration file to be created or modified to add the MCP server.

Note: The configuration file syntax can be different across clients. Please refer to the following links for the latest expected syntax:

- Windsurf: https://docs.windsurf.com/windsurf/mcp
- VSCode: https://code.visualstudio.com/docs/copilot/chat/mcp-servers
- Claude Desktop: https://modelcontextprotocol.io/quickstart/user
- Cursor: https://docs.cursor.com/context/model-context-protocol
- Copilot CLI: https://docs.github.com/en/copilot/concepts/agents/about-copilot-cli
- Opencode CLI: https://opencode.ai/docs/mcp-servers

> Default Safety Notice: All examples below include --readOnly by default to ensure safe, read-only access to your data. Remove --readOnly if you need to enable write operations.

Option 1: Connection String

You can pass your connection string via environment variables, make sure to use a valid username and password.

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

NOTE: The connection string can be configured to connect to any MongoDB cluster, whether it's a local instance or an Atlas cluster.

Option 2: Atlas API Credentials

Use your Atlas API Service Accounts credentials. Must follow all the steps in Atlas API Access section.

{
  "mcpServers": {
    "MongoDB": {
      "command": "npx",
      "args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
      "env": {
        "MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
        "MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
      }
    }
  }
}
Option 3: Standalone Service using environment variables and command line arguments

You can source environment variables defined in a config file or explicitly set them like we do in the example below and run the server via npx.

```shell

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.

Videos about MongoDB MCP Server

Relevant YouTube tutorials, setups, and demos