# MongoDB MCP server

> Query MongoDB databases and manage Atlas clusters from your AI assistant, with an optional read-only mode.

- Listing: https://mcp.tc/i/mongodb
- Connect: this is a local (stdio) server; install it on your machine (see Install). The listing link is a page, not an MCP endpoint.
- Type: local (stdio)
- Auth: API key
- Category: [Databases & Backend](https://mcp.tc/c/databases)
- Vendor: MongoDB
- Verified: yes, mcp.tc checked that this is the official server (https://mcp.tc/verify). It says who runs the server, not that it is safe.
- Homepage: <https://www.mongodb.com/docs/mcp-server/>
- Repository: <https://github.com/mongodb-js/mongodb-mcp-server>
- Package: npm `mongodb-mcp-server`

## About

Connects an AI assistant to MongoDB databases and MongoDB Atlas. It can work with data in self-managed or Atlas deployments through a connection string, and manage Atlas resources through the Atlas API. The README groups its tools into Atlas, database and MongoDB Assistant categories.

It runs locally over stdio as the npm package mongodb-mcp-server (also published as a Docker image) and needs Node.js 22.13 or later. Authentication uses a MongoDB connection string or Atlas service account API credentials, passed as environment variables. The --readOnly flag limits it to read operations. MongoDB also offers a hosted Atlas MCP server over OAuth through its agent plugins.

## What it can do

- Connect to MongoDB deployments with a connection string
- Work with MongoDB data through database tools
- Manage MongoDB Atlas resources with Atlas API credentials
- Run in read-only mode with the --readOnly flag
- Disable tools or require confirmation for selected tools
- Disable server-side JavaScript operators in queries

## Example prompts

- "List the collections in my MongoDB database"
- "Find the 10 most recent orders in the orders collection"
- "Show my Atlas clusters"
- "Describe the indexes on the users collection"

## Install

### Claude Code

1. Run this in a terminal, in your project folder:

```bash
claude mcp add --transport stdio mongodb --env "MDB_MCP_API_CLIENT_ID=<YOUR_MDB_MCP_API_CLIENT_ID>" --env "MDB_MCP_API_CLIENT_SECRET=<YOUR_MDB_MCP_API_CLIENT_SECRET>" --env "MDB_MCP_CONNECTION_STRING=<YOUR_MDB_MCP_CONNECTION_STRING>" -- npx -y mongodb-mcp-server@latest --readOnly
```

2. Start Claude Code and type `/mcp`. **mongodb** should show as connected.

Add `--scope user` to make it available in every project. Replace the placeholders with your own values.

### Claude Desktop

1. Open **Settings → Developer → Edit Config**. It opens `claude_desktop_config.json`. Add:

`claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server@latest",
        "--readOnly"
      ],
      "env": {
        "MDB_MCP_API_CLIENT_ID": "<YOUR_MDB_MCP_API_CLIENT_ID>",
        "MDB_MCP_API_CLIENT_SECRET": "<YOUR_MDB_MCP_API_CLIENT_SECRET>",
        "MDB_MCP_CONNECTION_STRING": "<YOUR_MDB_MCP_CONNECTION_STRING>"
      }
    }
  }
}
```

2. Save the file and restart Claude Desktop. Replace the placeholders with your own values.

Needs Node.js on your computer. The file lives in `~/Library/Application Support/Claude/` on macOS and `%APPDATA%\Claude\` on Windows.

### Cursor

[Add to Cursor](<https://cursor.com/install-mcp?name=mongodb&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIm1vbmdvZGItbWNwLXNlcnZlckBsYXRlc3QiLCItLXJlYWRPbmx5Il0sImVudiI6eyJNREJfTUNQX0FQSV9DTElFTlRfSUQiOiI8WU9VUl9NREJfTUNQX0FQSV9DTElFTlRfSUQ%2BIiwiTURCX01DUF9BUElfQ0xJRU5UX1NFQ1JFVCI6IjxZT1VSX01EQl9NQ1BfQVBJX0NMSUVOVF9TRUNSRVQ%2BIiwiTURCX01DUF9DT05ORUNUSU9OX1NUUklORyI6IjxZT1VSX01EQl9NQ1BfQ09OTkVDVElPTl9TVFJJTkc%2BIn19>) (opens Cursor)

Or add it by hand to `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (this project):

`mcp.json`:

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server@latest",
        "--readOnly"
      ],
      "env": {
        "MDB_MCP_API_CLIENT_ID": "<YOUR_MDB_MCP_API_CLIENT_ID>",
        "MDB_MCP_API_CLIENT_SECRET": "<YOUR_MDB_MCP_API_CLIENT_SECRET>",
        "MDB_MCP_CONNECTION_STRING": "<YOUR_MDB_MCP_CONNECTION_STRING>"
      }
    }
  }
}
```

Needs Node.js on your computer. Replace the placeholders with your own values.

### VS Code

Add it to `.vscode/mcp.json`. VS Code asks for the secret the first time and stores it securely:

`.vscode/mcp.json`:

```json
{
  "servers": {
    "mongodb": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server@latest",
        "--readOnly"
      ],
      "env": {
        "MDB_MCP_API_CLIENT_ID": "${input:mdb-mcp-api-client-id}",
        "MDB_MCP_API_CLIENT_SECRET": "${input:mdb-mcp-api-client-secret}",
        "MDB_MCP_CONNECTION_STRING": "${input:mdb-mcp-connection-string}"
      }
    }
  },
  "inputs": [
    {
      "type": "promptString",
      "id": "mdb-mcp-api-client-id",
      "description": "MDB_MCP_API_CLIENT_ID",
      "password": true
    },
    {
      "type": "promptString",
      "id": "mdb-mcp-api-client-secret",
      "description": "MDB_MCP_API_CLIENT_SECRET",
      "password": true
    },
    {
      "type": "promptString",
      "id": "mdb-mcp-connection-string",
      "description": "MDB_MCP_CONNECTION_STRING",
      "password": true
    }
  ]
}
```

Needs Node.js on your computer.

### Devin Desktop

1. Add it to `~/.config/devin/mcp_config.json` (macOS and Linux) or `%APPDATA%\devin\mcp_config.json` (Windows):

`mcp_config.json`:

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server@latest",
        "--readOnly"
      ],
      "env": {
        "MDB_MCP_API_CLIENT_ID": "<YOUR_MDB_MCP_API_CLIENT_ID>",
        "MDB_MCP_API_CLIENT_SECRET": "<YOUR_MDB_MCP_API_CLIENT_SECRET>",
        "MDB_MCP_CONNECTION_STRING": "<YOUR_MDB_MCP_CONNECTION_STRING>"
      }
    }
  }
}
```

2. Refresh the MCP server list in Cascade. Replace the placeholders with your own values.

Devin Desktop is the new name for Windsurf.

### Codex

```bash
codex mcp add mongodb --env "MDB_MCP_API_CLIENT_ID=<YOUR_MDB_MCP_API_CLIENT_ID>" --env "MDB_MCP_API_CLIENT_SECRET=<YOUR_MDB_MCP_API_CLIENT_SECRET>" --env "MDB_MCP_CONNECTION_STRING=<YOUR_MDB_MCP_CONNECTION_STRING>" -- npx -y mongodb-mcp-server@latest --readOnly
```

Or edit `~/.codex/config.toml` directly:

`config.toml`:

```toml
[mcp_servers.mongodb]
command = "npx"
args = ["-y", "mongodb-mcp-server@latest", "--readOnly"]
env = { MDB_MCP_API_CLIENT_ID = "<YOUR_MDB_MCP_API_CLIENT_ID>", MDB_MCP_API_CLIENT_SECRET = "<YOUR_MDB_MCP_API_CLIENT_SECRET>", MDB_MCP_CONNECTION_STRING = "<YOUR_MDB_MCP_CONNECTION_STRING>" }
```

Needs Node.js on your computer. Replace the placeholders with your own values.

### Gemini CLI

```bash
gemini mcp add -e "MDB_MCP_API_CLIENT_ID=<YOUR_MDB_MCP_API_CLIENT_ID>" -e "MDB_MCP_API_CLIENT_SECRET=<YOUR_MDB_MCP_API_CLIENT_SECRET>" -e "MDB_MCP_CONNECTION_STRING=<YOUR_MDB_MCP_CONNECTION_STRING>" mongodb npx -- -y mongodb-mcp-server@latest --readOnly
```

This adds it to the current project. Add `-s user` to use it everywhere.

### Any client

Most clients that start local servers accept this shape:

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server@latest",
        "--readOnly"
      ],
      "env": {
        "MDB_MCP_API_CLIENT_ID": "<YOUR_MDB_MCP_API_CLIENT_ID>",
        "MDB_MCP_API_CLIENT_SECRET": "<YOUR_MDB_MCP_API_CLIENT_SECRET>",
        "MDB_MCP_CONNECTION_STRING": "<YOUR_MDB_MCP_CONNECTION_STRING>"
      }
    }
  }
}
```

Zed puts servers under `context_servers` in its settings, with the same `command`, `args` and `env` fields.

Needs Node.js on your computer. Replace the placeholders with your own values.

## Details

- Server version: 2.1.0
- Last checked: 2026-10-03
- Listed: 2026-10-03
- Updated: 2026-10-03

---
Source: https://mcp.tc/i/mongodb (mcp.tc is an independent directory, not affiliated with this server's publisher). Corrections: https://mcp.tc/report
