home / mcp / mongodb mcp server

MongoDB MCP Server

Provides read/write access to MongoDB data via MCP clients, supporting connection strings and Atlas API credentials.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "aiminnovations-mongodb-mcp-juniper": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server@latest",
        "--readOnly"
      ],
      "env": {
        "MDB_MCP_LOG_PATH": "/path/to/logs",
        "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+srv://username:[email protected]/myDatabase"
      }
    }
  }
}

You can run a MongoDB MCP Server to interact with MongoDB databases and Atlas using a single, configurable MCP endpoint. This server exposes a set of MongoDB tools and Atlas tools, enabling read-only querying, data operations, and Atlas cluster management through MCP clients while keeping sensitive credentials secure via environment variables.

How to use

Choose a configuration method that fits your deployment. You can connect using a MongoDB connection string, authenticate with Atlas service account credentials, run a standalone setup with environment variables, or deploy via Docker. The server supports both read-only and full access modes depending on how you configure it. You can enable HTTP transport later if you need to expose the server over HTTP, but ensure you apply proper security measures.

How to install

Prerequisites: you need Node.js installed (any version that meets the MCP’s requirements) and a MongoDB connection string or Atlas API credentials.

Step 1: Prepare one of the MCP configurations shown below. Step 2: Start the MCP server per the chosen method.

MongoDB MCP Server configurations

[
  {
    "name": "mongodb_conn",
    "type": "stdio",
    "command": "npx",
    "args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
    "env": {
      "MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase"
    }
  },
  {
    "name": "mongodb_atlas",
    "type": "stdio",
    "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"
    }
  },
  {
    "name": "mongodb_standalone",
    "type": "stdio",
    "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+srv://username:[email protected]/myDatabase"
    }
  },
  {
    "name": "mongodb_docker",
    "type": "stdio",
    "command": "docker",
    "args": ["run", "--rm", "-i", "mongodb/mongodb-mcp-server:latest"]
  },
  {
    "name": "mongodb_docker_conn",
    "type": "stdio",
    "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://username:[email protected]/myDatabase"
    }
  },
  {
    "name": "mongodb_docker_atlas",
    "type": "stdio",
    "command": "docker",
    "args": ["run", "--rm", "-i", "-e", "MDB_MCP_READ_ONLY=true", "-e", "MDB_MCP_API_CLIENT_ID", "-e", "MDB_MCP_API_CLIENT_SECRET", "mongodb/mongodb-mcp-server:latest"],
    "env": {
      "MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
      "MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
    }
  }
]

Proxy and transport notes

By default, the MCP server uses stdio transport suitable for integration with MCP clients. If you need to interact over HTTP, you can enable the HTTP transport with the appropriate startup flag, but ensure you apply strong security controls such as authentication, TLS, and network controls.

Security and best practices

Always prefer environment variables for sensitive configuration like connection strings and API credentials. Enable read-only mode if you only need data analysis access. Use a restricted Atlas API service account with minimum required permissions. Consider deploying behind a firewall or in a private network, and enable authentication when exposing the server via HTTP.

Atlas API Access

To use Atlas API tools, create a service account in MongoDB Atlas and grant only the minimum permissions needed for your tasks. Then configure the MCP server with the credentials in one of the supported configuration methods.

Configuration methods

Environment variables provide a secure way to supply credentials. The MCP server also supports command-line arguments for configuration, but sensitive values should be passed via environment variables whenever possible.

Troubleshooting and notes

If you encounter connectivity issues, verify that the connection string is correct, the Atlas service account has the proper permissions, and the MCP server has access to external endpoints through any required proxies.

Contributing

If you want to contribute, follow established guidelines for contributing, debugging, and troubleshooting to help improve the MongoDB MCP Server.

Available tools

atlas-list-orgs

Lists MongoDB Atlas organizations

atlas-list-projects

Lists MongoDB Atlas projects

atlas-create-project

Creates a new MongoDB Atlas project

atlas-list-clusters

Lists MongoDB Atlas clusters

atlas-inspect-cluster

Inspect a specific MongoDB Atlas cluster

atlas-create-free-cluster

Create a free MongoDB Atlas cluster

atlas-connect-cluster

Connects to MongoDB Atlas cluster

atlas-inspect-access-list

Inspect IP/CIDR ranges with access to MongoDB Atlas clusters

atlas-create-access-list

Configure IP/CIDR access list for Atlas clusters

atlas-list-db-users

List Atlas users

atlas-create-db-user

Creates Atlas database user

atlas-list-alerts

List Atlas project alerts

connect

Connect to a MongoDB instance

find

Run a find query against a collection

aggregate

Run an aggregation against a collection

count

Get the number of documents in a collection

insert-one

Insert a single document into a collection

insert-many

Insert multiple documents into a collection

create-index

Create an index for a collection

update-one

Update a single document in a collection

update-many

Update multiple documents in a collection

rename-collection

Rename a MongoDB collection

delete-one

Delete a single document from a collection

delete-many

Delete multiple documents from a collection

drop-collection

Remove a collection from a database

drop-database

Remove a MongoDB database

list-databases

List all databases for a connection

list-collections

List all collections for a database

collection-indexes

Describe indexes for a collection

collection-schema

Describe the schema for a collection

collection-storage-size

Get the size of a collection in MB

db-stats

Return statistics about a MongoDB database

export

Export query or aggregation results to EJSON format

atlas-list-orgs_placeholder

Atlas placeholder tool example

MongoDB MCP Server - aiminnovations/mongodb-mcp-juniper