/ Directory / Playground / MongoDB MCP Server
● Community kiliczsh 🔑 Needs your key

MongoDB MCP Server

by kiliczsh · kiliczsh/mcp-mongo-server

Hand Claude a MongoDB connection string and let it query, aggregate, and inspect schemas — with a --read-only flag for production safety.

mcp-mongo-server is a no-frills MCP server for MongoDB. Pass a connection URI as the only argument and Claude gets find, aggregate, indexes, schema inference, and collection introspection. Ships a --read-only flag that strips all mutating tools — use it when you want Claude to explore prod without touching it.

Why use it

Key features

Live Demo

What it looks like in practice

mongo-mcp-kiliczsh.replay ▶ ready
0/0

Install

Pick your client

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "mongo-mcp-kiliczsh": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://localhost:27017/mydb"
      ]
    }
  }
}

Open Claude Desktop → Settings → Developer → Edit Config. Restart after saving.

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "mongo-mcp-kiliczsh": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://localhost:27017/mydb"
      ]
    }
  }
}

Cursor uses the same mcpServers schema as Claude Desktop. Project config wins over global.

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "mongo-mcp-kiliczsh": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://localhost:27017/mydb"
      ]
    }
  }
}

Click the MCP Servers icon in the Cline sidebar, then "Edit Configuration".

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "mongo-mcp-kiliczsh": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://localhost:27017/mydb"
      ]
    }
  }
}

Same shape as Claude Desktop. Restart Windsurf to pick up changes.

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "mongo-mcp-kiliczsh",
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://localhost:27017/mydb"
      ]
    }
  ]
}

Continue uses an array of server objects rather than a map.

~/.config/zed/settings.json
{
  "context_servers": {
    "mongo-mcp-kiliczsh": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "mcp-mongo-server",
          "mongodb://localhost:27017/mydb"
        ]
      }
    }
  }
}

Add to context_servers. Zed hot-reloads on save.

claude mcp add mongo-mcp-kiliczsh -- npx -y mcp-mongo-server mongodb://localhost:27017/mydb

One-liner. Verify with claude mcp list. Remove with claude mcp remove.

Use Cases

Real-world ways to use MongoDB MCP Server

Explore an unfamiliar MongoDB database without writing anything

👤 Devs onboarding to a new service ⏱ ~15 min beginner

When to use: You inherited a Mongo instance and the schema is undocumented.

Prerequisites
  • Read-only Mongo user — db.createUser({user:'reader', roles:[{role:'read', db:'mydb'}]})
Flow
  1. Connect read-only
    Use the mongo MCP. List all collections and infer the schema for the top 3 by size.✓ Copied
    → Collection list + JSON schema per collection
  2. Spot-check
    Show me 5 sample documents from orders — anonymize emails.✓ Copied
    → 5 docs, PII redacted
  3. Map relationships
    Which collections reference each other by ObjectId? Draw a quick text diagram.✓ Copied
    → Plain-text ER diagram

Outcome: Working mental model of the database in 10 minutes, no DBA needed.

Pitfalls
  • Sampling miss high-cardinality fields — Increase sample size in inference call; sample by date if data is time-skewed
Combine with: filesystem

Tune a slow aggregation with index advice from Claude

👤 Backend devs ⏱ ~25 min intermediate

When to use: An aggregation pipeline takes 30s and you don't know which stage is the cost.

Flow
  1. Profile
    Run this aggregation with explain=true. Show the winning plan.✓ Copied
    → Explain output with stage docs scanned
  2. Diagnose
    Which stage is the bottleneck? What index would help?✓ Copied
    → Concrete index suggestion with rationale
  3. Verify
    Re-explain after I add the index. Did totalDocsExamined drop?✓ Copied
    → Yes/no with numbers

Outcome: Aggregation that's 10x faster with one targeted index.

Pitfalls
  • Claude suggests an index that bloats writes — Ask: 'What write penalty does this index add?' before applying

Find documents that violate an implicit schema

👤 Data engineers ⏱ ~20 min intermediate

When to use: Schemaless DBs accumulate drift; you need to find offenders.

Flow
  1. Sample
    Sample 1000 documents from users. What fields are missing or have unexpected types?✓ Copied
    → Per-field nullity / type-frequency table
  2. Find
    Find all users where email is null or not a string.✓ Copied
    → Count + sample _ids

Outcome: Concrete dirty-data report you can hand to migration scripts.

Pitfalls
  • Large collections hit timeouts — Use $sample then scope follow-ups by ranges

Combinations

Pair with other MCPs for X10 leverage

mongo-mcp-kiliczsh + filesystem

Export aggregation results to JSON for downstream tools

Run the aggregation and save results to /tmp/orders-by-month.json.✓ Copied
mongo-mcp-kiliczsh + github

Open a PR with a migration script after spotting drift

We found 1200 users without email. Open a PR with a backfill migration.✓ Copied

Tools

What this MCP exposes

ToolInputsWhen to callCost
find collection, filter, projection?, limit? Look up specific docs 1 query
aggregate collection, pipeline[], explain? Group/transform data 1 query
list_collections (none) Discover what's in the DB free
schema collection, sample_size? Infer shape from sampled docs 1 sample read
list_indexes collection Tuning conversations free
insert_one collection, document Only when not in --read-only mode 1 write

Cost & Limits

What this costs to run

API quota
Bound by your Mongo cluster's RU/IOPS
Tokens per call
200–5000 depending on result size
Monetary
Free (open source)
Tip
Project only the fields you need; cap limit early

Security

Permissions, secrets, blast radius

Minimum scopes: read on the target db
Credential storage: URI passed as CLI arg — keep it out of shell history
Data egress: Only to your Mongo host
Never grant: dbAdmin root

Troubleshooting

Common errors and fixes

MongoServerSelectionError

Check connectivity, IP allowlist, TLS settings

Verify: mongosh with the same URI
Authentication failed

Check authSource in URI (often admin); confirm user exists in that DB

Tool not found in read-only mode

Drop --read-only if you need writes; otherwise use a different MCP for writes

Alternatives

MongoDB MCP Server vs others

AlternativeWhen to use it insteadTradeoff
MongoDB CompassGUI exploration, no AI involvedNo agent integration; manual queries
mongosh in a shell MCPYou want raw mongosh powerMore dangerous; this MCP gives bounded tools

More

Resources

📖 Read the official README on GitHub

🐙 Browse open issues

🔍 Browse all 400+ MCP servers and Skills

Continue exploring

Related tools and workflows

Choose another guide for your workflow, or explore a collection.

Same topic collection

MongoDB Agent Skills

Use MongoDB’s official skills for query writing, schema design, query optimization, Atlas Search, and Vector Search.

Skill

Same collection group

Milvus MCP

Connect an MCP client to Milvus for vector search, collection inspection, and vector-database operations.

MCP

Same collection group

Redis

Use Redis’s MCP server to work with Redis data and database operations.

MCP

Same topic collection

Apache Doris MCP

Expose read-only Apache Doris capabilities through a server with domain discovery, explicit authorization, and bounded query results.

MCP

Browse all topic collections → · See 29 new official additions →