MongoDB MCP server

Provides a bridge between MongoDB databases and conversational interfaces, enabling comprehensive database operations, collection management, schema inspection, and Atlas cloud service interactions with authentication and telemetry support.
Back to servers
Setup instructions
Provider
MongoDB Inc.
Release date
Apr 29, 2025
Language
TypeScript
Package
Stats
120.1K downloads
611 stars

The MongoDB MCP Server provides a Model Context Protocol interface for interacting with MongoDB databases and MongoDB Atlas. This tool allows AI assistants to directly query and manage MongoDB resources through a standardized protocol.

Installation and Setup

Prerequisites

Before using the MongoDB MCP Server, ensure you have:

  • Node.js: Version 20.19.0+ or 22.12.0+ or any 23+ version
  • MongoDB Connection String or Atlas API Credentials

Quick Start

The MongoDB MCP Server can be installed and configured in several ways. Here are the most common approaches, all using the --readOnly flag by default to ensure safe access.

Using NPX with a Connection String

npx -y mongodb-mcp-server --connectionString mongodb://localhost:27017/myDatabase --readOnly

Using NPX with Atlas API Credentials

npx -y mongodb-mcp-server --apiClientId "your-atlas-service-accounts-client-id" --apiClientSecret "your-atlas-service-accounts-client-secret" --readOnly

Using Docker

docker run --rm -i \
  -e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:[email protected]/myDatabase" \
  -e MDB_MCP_READ_ONLY="true" \
  mongodb/mongodb-mcp-server:latest

Running as an HTTP Server

npx -y mongodb-mcp-server --transport http --httpHost=127.0.0.1 --httpPort=3000

⚠️ Security Notice: HTTP transport is NOT recommended for production use without implementing proper authentication and security measures.

Supported Tools

MongoDB Atlas 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 MongoDB Atlas clusters
  • atlas-list-db-users - List MongoDB Atlas database users
  • atlas-create-db-user - Creates a MongoDB Atlas database user
  • atlas-list-alerts - List MongoDB Atlas Alerts for a Project

MongoDB Database Tools

  • connect - Connect to a MongoDB instance
  • find - Run a find query against a MongoDB collection
  • aggregate - Run an aggregation against a MongoDB collection
  • count - Get the number of documents in a MongoDB collection
  • insert-one - Insert a single document into a MongoDB collection
  • insert-many - Insert multiple documents into a MongoDB collection
  • create-index - Create an index for a MongoDB collection
  • update-one - Update a single document in a MongoDB collection
  • update-many - Update multiple documents in a MongoDB collection
  • rename-collection - Rename a MongoDB collection
  • delete-one - Delete a single document from a MongoDB collection
  • delete-many - Delete multiple documents from a MongoDB collection
  • drop-collection - Remove a collection from a MongoDB database
  • drop-database - Remove a MongoDB database
  • list-databases - List all databases for a MongoDB connection
  • list-collections - List all collections for a given database
  • collection-indexes - Describe the 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

Configuration Options

The server supports various configuration options that can be set via command-line arguments or environment variables:

Connection Options

  • connectionString (env: MDB_MCP_CONNECTION_STRING) - MongoDB connection string
  • apiClientId (env: MDB_MCP_API_CLIENT_ID) - Atlas API client ID
  • apiClientSecret (env: MDB_MCP_API_CLIENT_SECRET) - Atlas API client secret

Safety Options

  • readOnly (env: MDB_MCP_READ_ONLY) - When true, only allows read operations
  • indexCheck (env: MDB_MCP_INDEX_CHECK) - When true, rejects queries that don't use an index
  • disabledTools (env: MDB_MCP_DISABLED_TOOLS) - Tools to disable (comma-separated)

Server Options

  • transport (env: MDB_MCP_TRANSPORT) - Either 'stdio' or 'http'
  • httpPort (env: MDB_MCP_HTTP_PORT) - Port number (default: 3000)
  • httpHost (env: MDB_MCP_HTTP_HOST) - Host to bind (default: 127.0.0.1)
  • loggers (env: MDB_MCP_LOGGERS) - Where to send logs (disk,mcp,stderr)
  • logPath (env: MDB_MCP_LOG_PATH) - Folder to store logs

Atlas API Access

To use the Atlas API tools:

  1. Create a service account in MongoDB Atlas with appropriate permissions
  2. Save the Client ID and Secret
  3. Add your IP address to the API access list
  4. Configure the MCP Server with your credentials

For example, to list projects with minimum permissions, assign the "Organization Read Only" role to your service account.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "MongoDB" '{"command":"npx","args":["-y","mongodb-mcp-server"],"env":{"MDB_MCP_CONNECTION_STRING":"mongodb://localhost:27017/myDatabase"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later