home / mcp / mongodb mcp server

MongoDB MCP Server

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

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "mongodb-js-mongodb-mcp-server": {
      "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",
        "MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
      }
    }
  }
}

You can run the MongoDB MCP Server to interact with MongoDB databases and Atlas using a Model Context Protocol client. It supports read-only access, Atlas API tools, and a variety of MongoDB tools, exposed through a configurable MCP interface that can run locally or as a service in containers or HTTP endpoints.

How to use

You deploy the MongoDB MCP Server and connect to it with an MCP client. Start with a ready configuration that provides either a MongoDB connection string or Atlas API credentials. Run the server in a mode that best fits your environment (local stdio, Docker container, or an HTTP transport when needed). Once running, your MCP client can invoke the MongoDB tools, manage databases and collections, perform queries, and, if permitted, write operations.

How to install

Prerequisites you need before starting: a supported Node.js runtime, and a valid MongoDB connection string or Atlas API credentials. Use environment variables for sensitive data when possible.

Step-by-step setup using a local stdio configuration with an environment-provided connection string:

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

If you prefer Atlas API credentials, configure them similarly in your MCP configuration.

{
  "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"
      }
    }
  }
}

You can also run a standalone server using environment variables and the command line, then start with npx, as shown in the examples.

Additional sections

Configuration and security considerations are central to using the MongoDB MCP Server effectively. Use environment variables for sensitive data, enable read-only mode when you only need data access, and consider enabling or disabling tools to match your security posture.

Configuration

The server supports multiple configuration methods with a recommended preference order: environment variables, then command-line arguments, then configuration files. Sensitive information should be supplied via environment variables whenever possible.

Below are common configuration patterns you may encounter. The examples show how you can provide a MongoDB connection string or Atlas API credentials to the server.

Available tools

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

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.

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.

atlas-connect-cluster

Connect to MongoDB Atlas cluster

atlas-create-access-list

Allow IP/CIDR ranges to access your MongoDB Atlas clusters.

atlas-create-db-user

Create a 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

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 MongoDB Atlas alerts

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-local-connect-deployment

Connect to a MongoDB Atlas Local deployment

atlas-local-create-deployment

Create a MongoDB Atlas local deployment

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.

search-knowledge

Search for information in the MongoDB Assistant knowledge base.