MongoDB MCP Server

by yairsabag

300 downloads
Not rated
GitHub

Description

# MongoDB MCP Server A Model Context Protocol server for interacting with MongoDB Databases and MongoDB Atlas. ## ๐Ÿ“š Table of Contents - [๐Ÿš€ Getting Started](#getting-started) - [Prerequisites](#prerequisites) - [Setup](#setup) - [Quick Start](#quick-start) - [๐Ÿ› ๏ธ Supportedโ€ฆ

About

# MongoDB MCP Server A Model Context Protocol server for interacting with MongoDB Databases and MongoDB Atlas. ## ๐Ÿ“š Table of Contents - [๐Ÿš€ Getting Started](#getting-started) - [Prerequisites](#prerequisites) - [Setup](#setup) - [Quick Start](#quick-start) - [๐Ÿ› ๏ธ Supported Tools](#supported-tools) - [MongoDB Atlasโ€ฆ

Details

Author
yairsabag
Downloads
300
Categories
Database

- Supports MongoDB Atlas administrative tools and direct database operations
- Configurable via command-line arguments, environment variables, or MCP client config
- Read-only mode restricts tools to read and metadata operations only
- Tool disabling by name, operation type, or category (atlas, mongodb)
- Docker support for isolated execution without local Node.js
- Telemetry collection can be disabled via configuration or DO_NOT_TRACK

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

Requires Node.js v20.10.0+ and either a MongoDB connection string or Atlas API credentials; the server will not start without these. Run via npx -y mongodb-mcp-server with command-line arguments or environment variables, or use a Docker container. Configuration can be placed in an MCP client settings file (e.g., for Windsurf, VSCode, Claude Desktop, Cursor). Tools are divided into Atlas management and database CRUD categories.

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.

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.

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

atlas-connect-cluster

Connect to MongoDB Atlas cluster 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.

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, single or multi-region). 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. For encryption at rest, the CMK provider must already have a valid configuration in the Atlas project. 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. Note to LLM: Omit instance size unless specified by the user. If provider and regions are not already known, ask for both together in a single question before calling this tool. Common, non-exhaustive region default mappings by provider: 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 North" โ†’ EUROPE_NORTH, "Europe West" โ†’ EUROPE_WEST. Default recommendation: AWS US_EAST_1. User-specified regions not present in the mapping MUST be respected, rely on the tool to surface errors if a region is not supported.

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 (Free and Flex clusters cannot be paused). Pause: paused clusters are unavailable for connections and do not incur compute costs. If the cluster being paused is the current active connection, it will be automatically disconnected. Returns an error if the cluster is already paused or not in a pausable state (must be IDLE). Resume: the cluster will not be immediately available after resuming. Use the atlas-inspect-cluster tool to poll the cluster state for readiness (state: IDLE). If the cluster is not paused, resuming it is a no-op.

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.

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-mcp-server-new": {
                "command": "npx",
                "args": [
                    "-y",
                    "mongodb-mcp-server",
                    "--apiClientId=your-atlas-service-accounts-client-id",
                    "--apiClientSecret=your-atlas-service-accounts-client-secret"
                ]
            }
        }
    }
}

McpServers

{
    "mongodb-mcp-server-new": {
        "command": "npx",
        "args": [
            "-y",
            "mongodb-mcp-server",
            "--apiClientId=your-atlas-service-accounts-client-id",
            "--apiClientSecret=your-atlas-service-accounts-client-secret"
        ]
    }
}

MongoDB MCP Server

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
- โš™๏ธ Configuration
- Configuration Options
- Atlas API Access
- Configuration Methods
- Environment Variables
- Command-Line Arguments
- MCP Client Configuration
- ๐Ÿค Contributing

Prerequisites

- Node.js (v20.10.0 or later)

node -v

- A MongoDB connection string or Atlas API credentials, _the Server will not start unless configured_.
- _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

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

Option 1: Connection String args

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

{
  "mcpServers": {
    "MongoDB": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString",
        "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 args

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",
        "--apiClientId",
        "your-atlas-service-accounts-client-id",
        "--apiClientSecret",
        "your-atlas-service-accounts-client-secret"
      ]
    }
  }
}

Option 3: Standalone Service using command arguments

Start Server using npx command:

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

- For a complete list of arguments see Configuration Options
- To configure your Atlas Service Accounts credentials please refer to Atlas API Access

Option 4: Standalone Service using environment variables

 npx -y mongodb-mcp-server

You can use environment variables in the config file or set them and run the server via npx.

- Connection String via environment variables in the MCP file example
- Atlas API credentials via environment variables in the MCP file example

Option 5: Using Docker

You can run the MongoDB MCP Server in a Docker container, which provides isolation and doesn't require a local Node.js installation.

Run with Environment Variables

You may provide either a MongoDB connection string OR Atlas API credentials:

Option A: No configuration
docker run --rm -i \
  mongodb/mongodb-mcp-server:latest
Option B: With MongoDB connection string
docker run --rm -i \
  -e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" \
  mongodb/mongodb-mcp-server:latest
Option C: With Atlas API credentials
docker run --rm -i \
  -e MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id" \
  -e MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret" \
  mongodb/mongodb-mcp-server:latest
Docker in MCP Configuration File

Without options:

{
  "mcpServers": {
    "MongoDB": {
      "command": "docker",
      "args": ["run", "--rm", "-i", "mongodb/mongodb-mcp-server:latest"]
    }
  }
}

With connection string:

{
  "mcpServers": {
    "MongoDB": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        "MDB_MCP_CONNECTION_STRING=mongodb+srv://username:password@cluster.mongodb.net/myDatabase",
        "mongodb/mongodb-mcp-server:latest"
      ]
    }
  }
}

With Atlas API credentials:

{
  "mcpServers": {
    "MongoDB": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        "MDB_MCP_API_CLIENT_ID=your-atlas-service-accounts-client-id",
        "-e",
        "MDB_MCP_API_CLIENT_SECRET=your-atlas-service-accounts-client-secret",
        "mongodb/mongodb-mcp-server:latest"
      ]
    }
  }
}

๐Ÿ› ๏ธ Supported Tools

Tool List

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

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

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

Configuration

The MongoDB MCP Server can be configured using multiple methods, with the following precedence (highest to lowest):

1. Command-line arguments
2. Environment variables

Configuration Options

| Option | Description |
| ------------------ | --------------------------------------------------------------------------------------------------------------------- |
| apiClientId | Atlas API client ID for authentication |
| apiClientSecret | Atlas API client secret for authentication |
| connectionString | MongoDB connection string for direct database connections (optional users may choose to inform it on every tool call) |
| logPath | Folder to store logs |
| disabledTools | An array of tool names, operation types, and/or categories of tools that will be disabled |
| readOnly | When set to true, only allows read and metadata operation types, disabling create/update/delete operations |
| telemetry | When set to disabled, disables telemetry collection |

Log Path

Default log location is as follows:

- Windows: %LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs
- macOS/Linux: ~/.mongodb/mongodb-mcp/.app-logs

Disabled Tools

You can disable specific tools or categories of tools by using the disabledTools option. This option accepts an array of strings,
where each string can be a tool name, operation type, or category.

The way the array is constructed depends on the type of configuration method you use:

- For environment variable configuration, use a comma-separated string: export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema".
- For command-line argument configuration, use a space-separated string: --disabledTools create update delete atlas collectionSchema.

Categories of tools:

- atlas - MongoDB Atlas tools, such as list clusters, create cluster, etc.
- mongodb - MongoDB database tools, such as find, aggregate, etc.

Operation types:

- create - Tools that create resources, such as create cluster, insert document, etc.
- update - Tools that update resources, such as update document, rename collection, etc.
- delete - Tools that delete resources, such as delete document, drop collection, etc.
- read - Tools that read resources, such as find, aggregate, list clusters, etc.
- metadata - Tools that read metadata, such as list databases, list collections, collection schema, etc.

Read-Only Mode

The readOnly configuration option allows you to restrict the MCP server to only use tools with "read" and "metadata" operation types. When enabled, all tools that have "create", "update" or "delete" operation types will not be registered with the server.

This is useful for scenarios where you want to provide access to MongoDB data for analysis without allowing any modifications to the data or infrastructure.

You can enable read-only mode using:

- Environment variable: export MDB_MCP_READ_ONLY=true
- Command-line argument: --readOnly

When read-only mode is active, you'll see a message in the server logs indicating which tools were prevented from registering due to this restriction.

Telemetry

The telemetry configuration option allows you to disable telemetry collection. When enabled, the MCP server will collect usage data and send it to MongoDB.

You can disable telemetry using:

- Environment variable: export MDB_MCP_TELEMETRY=disabled
- Command-line argument: --telemetry disabled
- DO_NOT_TRACK environment variable: export DO_NOT_TRACK=1

Atlas API Access

To use the Atlas API tools, you'll need to create a service account in MongoDB Atlas:

1. Create a Service Account:

- Log in to MongoDB Atlas at cloud.mongodb.com
- Navigate to Access Manager > Organization Access
- Click Add New > Applications > Service Accounts
- Enter name, description and expiration for your service account (e.g., "MCP, MCP Server Access, 7 days")
- Select appropriate permissions (for full access, use Organization Owner)
- Click "Create"

To learn more about Service Accounts, check the MongoDB Atlas documentation.

2. Save Client Credentials:

- After creation, you'll be shown the Client ID and Client Secret
- Important: Copy and save the Client Secret immediately as it won't be displayed again

3. Add Access List Entry:

- Add your IP address to the API access list

4. Configure the MCP Server:
- Use one of the configuration methods below to set your apiClientId and apiClientSecret

Configuration Methods

Environment Variables

Set environment variables with the prefix MDB_MCP_ followed by the option name in uppercase with underscores:

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