# MongoDB

> Query and inspect MongoDB collections from Claude, Cursor, and VS Code.

[Canonical HTML page](https://top-mcps.com/mcp/mongodb) · [server.json](https://top-mcps.com/mcp/mongodb.json) · [methodology](https://top-mcps.com/about/methodology)

## Install

### Claude Desktop — `claude_desktop_config.json`

Paste under mcpServers. Fully quit and reopen Claude after editing.

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\""
      ],
      "env": {
        "MDB_CONNECTION_STRING": "${MDB_CONNECTION_STRING}"
      }
    }
  }
}
```

### Claude Code — `CLI or .mcp.json`

Run from your repo. Commit .mcp.json to share with your team.

```shell
# export MDB_CONNECTION_STRING=mongodb+srv://user:pass@cluster.mongodb.net
claude mcp add mongodb -- npx -y mongodb-mcp-server --connectionString="mongodb+srv://user:pass@cluster.mongodb.net"
```

### Cursor — `.cursor/mcp.json`

Global path: ~/.cursor/mcp.json. Reload window after editing.

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\""
      ],
      "env": {
        "MDB_CONNECTION_STRING": "${MDB_CONNECTION_STRING}"
      }
    }
  }
}
```

### VS Code — `.vscode/mcp.json`

VS Code uses the "servers" key (not "mcpServers").

```jsonc
{
  "servers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\""
      ],
      "env": {
        "MDB_CONNECTION_STRING": "${MDB_CONNECTION_STRING}"
      }
    }
  }
}
```

### Windsurf — `~/.codeium/windsurf/mcp_config.json`

Open via Cascade → hammer icon → Configure.

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\""
      ],
      "env": {
        "MDB_CONNECTION_STRING": "${MDB_CONNECTION_STRING}"
      }
    }
  }
}
```

### Cline — `cline_mcp_settings.json`

Open via the Cline sidebar → MCP Servers → Edit.

```json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\""
      ],
      "env": {
        "MDB_CONNECTION_STRING": "${MDB_CONNECTION_STRING}"
      }
    }
  }
}
```

### Continue — `~/.continue/config.json`

Continue uses modelContextProtocolServers with a transport block.

```json
{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "npx",
          "args": [
            "-y",
            "mongodb-mcp-server",
            "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\""
          ],
          "env": {
            "MDB_CONNECTION_STRING": "${MDB_CONNECTION_STRING}"
          }
        }
      }
    ]
  }
}
```

### Codex CLI — `~/.codex/config.toml`

Codex uses TOML. Each server is a [mcp_servers.<name>] subtable.

```shell
# ~/.codex/config.toml
[mcp_servers.mongodb]
command = "npx"
args = [
  "-y",
  "mongodb-mcp-server",
  "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\"",
]
env = { MDB_CONNECTION_STRING = "${MDB_CONNECTION_STRING}" }
```

### Zed — `~/.config/zed/settings.json`

Zed calls them "context_servers". Settings live-reload on save.

```jsonc
{
  "context_servers": {
    "mongodb": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "mongodb-mcp-server",
          "--connectionString=\"mongodb+srv://user:pass@cluster.mongodb.net\""
        ]
      },
      "env": {
        "MDB_CONNECTION_STRING": "${MDB_CONNECTION_STRING}"
      }
    }
  }
}
```

### ChatGPT — `ChatGPT → Apps directory`

MongoDB doesn't ship a hosted HTTPS endpoint today. ChatGPT supports remote MCP servers only — to use this server in ChatGPT you'll need to deploy it to a public HTTPS URL first (e.g. via Cloudflare Workers or Vercel) or wait for an official remote build.

```none

```

## At a glance

- **Maintainer:** MongoDB
- **Transport:** stdio
- **Auth model:** API key
- **Required secrets:** MDB_CONNECTION_STRING
- **Supported clients:** Claude, Cursor, VS Code, Windsurf, Any MCP-compatible client, MongoDB 5+, MongoDB Atlas
- **License:** Apache-2.0
- **Language:** TypeScript
- **Latest version:** latest
- **Last verified:** 2026-05-27
- **GitHub stars:** 1,038 (fetched 2026-06-02T11:55:52.290Z)
- **Score:** 89/100 (rubric 2026-04 — see https://top-mcps.com/about/methodology)
- **Source:** https://github.com/mongodb-js/mongodb-mcp-server

## Tools & permissions

| Tool | Description | Args | Side effects |
|------|-------------|------|--------------|
| `list_databases` | List databases on the cluster. | `—` | read |
| `list_collections` | List collections within a database. | `database: string` | read |
| `find` | Run a find query against a collection. | `collection: string, filter?: object` | read |
| `aggregate` | Run an aggregation pipeline. | `collection: string, pipeline: array` | read |

## Security & scope

- **Access scope:** read-only
- **Sandbox:** Connects via standard MongoDB driver to the connection string in MDB_CONNECTION_STRING. Read-only mode disables write tools at the MCP layer; combine with a database user scoped to the smallest namespace your workflow needs.
- **Gotchas:**
  - Read-only is enforced at the tool level, not the MongoDB role. Always pair MCP read-only mode with a read-only database user.
  - Schema inference samples N documents; rare fields may be missing from the inferred schema.
  - The Atlas Admin tools require a separate Atlas API key — do not reuse the connection-string password for admin scope.

## Quick answer

**What it does.** Connects to a MongoDB deployment and exposes database/collection enumeration, schema inspection, find queries, and aggregation pipelines to AI models.

**Best for:**
- Collection schema exploration
- Aggregation pipeline drafting
- Document inspection
- Reporting queries
- Index review

**Not for:**
- Transactional multi-document writes
- Long-running Change Streams
- Sharded-cluster ops work

## Description

The official MongoDB MCP connects an AI agent to a MongoDB cluster — list databases, inspect collection schemas, run aggregations, and execute find/count queries. Supports Atlas, self-hosted MongoDB, and connection-string-based auth. The server ships read-only and write-capable modes; the safe default is read-only for any agent-driven conversation.

## Why it matters

MongoDB is the most-installed document store. Wiring it into an agent unblocks schema exploration, ad-hoc reporting, and the "what is in this collection again" workflow without breaking out a separate client.

## Key features

- Atlas + self-hosted support
- Connection-string auth
- Schema inference per collection
- Read-only mode by default
- Aggregation pipeline execution
- Index introspection

## FAQ

### Does it support MongoDB Atlas?

Yes — pass the standard SRV connection string from the Atlas UI. The MCP also wraps Atlas Admin endpoints when you provide an Atlas API key, but you can run pure-data workflows without those scopes.

### Read-only or read-write?

Both. Read-only is the safe default. Pass --readOnly=false (or set MDB_READ_ONLY=false) to enable insert/update/delete tools — only do this on dev clusters.

### How does it infer schema?

It samples a configurable number of documents per collection and returns the union of field types. Useful for the model, but treat the result as a sketch — not a contract.

### Can I scope to one database?

Yes. Pass --database=<name> to restrict every tool to that database. Combine with a database user that only has access to that namespace as defence in depth.

### Does it support transactions?

No agent-facing transaction tool by design — multi-statement consistency in an LLM conversation is a footgun. Use a regular MongoDB driver for transactional workloads.

## Changelog

- **2026-05-27** — Refreshed install snippets and fact sheet; verified for 2026.
- **2025-04-22** — Initial directory listing.
