MCP Directory

MCP MongoDB Server

Let LLMs query, aggregate, and write to MongoDB with schema inference and read-only protection.

Unverified
stdio (local)
No auth
TypeScript

Add to your client

Copy the config for your MCP client and paste it into its config file.

Install / run
npx -y mcp-mongo-server mongodb://localhost:27017/database

Paste into ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mcp-mongodb-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://username:password@localhost:27017/database"
      ]
    }
  }
}

Step-by-step guides: Add to Claude Desktop · Add to Cursor · Add to Windsurf

Before you start

  • Node.js with npx (to run the package), or Docker
  • A reachable MongoDB instance and a connection URI

About MCP MongoDB Server

MCP MongoDB Server connects MCP-compatible clients (Claude Desktop, Cursor, Windsurf, Cline) to a MongoDB database over stdio. It infers collection schemas from document samples, auto-completes collection names, and exposes tools for querying, aggregating, counting, and (outside read-only mode) inserting, updating, and creating indexes. Queries and aggregations support optional explain plans, and a configurable ObjectId handling mode controls automatic string-to-ObjectId conversion.

Tools & capabilities (7)

query

Execute MongoDB queries with filter, projection, and limit options, plus an optional explain plan (e.g. executionStats).

aggregate

Run MongoDB aggregation pipelines, with an optional explain plan (e.g. queryPlanner).

count

Count documents in a collection that match a query.

update

Modify documents matching a filter, with upsert and multi options (disabled in read-only mode).

insert

Insert one or more new documents into a collection (disabled in read-only mode).

createIndex

Create one or more indexes on a collection, including unique and named indexes (disabled in read-only mode).

serverInfo

Get MongoDB server details, with optional debug information.

When to use it

  • Let an LLM explore an unfamiliar MongoDB database by inferring collection schemas and running ad-hoc queries.
  • Run aggregation pipelines and inspect explain plans to analyze or debug query performance.
  • Safely give an assistant read-only analytics access to production data via read-only mode.
  • Perform assisted data maintenance such as bulk inserts, updates, and index creation.

Security notes

Credentials are passed through the MongoDB connection URI (in args or the MCP_MONGODB_URI env var), so they will be stored in plaintext in your MCP client config. Use the --read-only flag (or MCP_MONGODB_READONLY="true") to block write operations and route reads to a secondary; read-only mode also disables the update, insert, and createIndex tools.

MCP MongoDB Server FAQ

How do I run it in read-only mode?

Append the --read-only flag to the command args, or set the MCP_MONGODB_READONLY environment variable to "true". Read-only mode blocks write operations and uses a secondary read preference.

How do I provide the MongoDB connection string?

Pass the URI as a positional argument (e.g. npx -y mcp-mongo-server mongodb://user:pass@host:27017/db), or set the MCP_MONGODB_URI environment variable instead of an argument.

Can I use it without npm?

Yes. You can run it directly from GitHub (npx -y github:kiliczsh/mcp-mongo-server ...) or build and run the provided Docker image. Smithery and mcp-get automated installers are also documented.

Alternatives to MCP MongoDB Server

Compare all alternatives →

Google's official MCP server with prebuilt BigQuery tools, querying datasets via Application Default Credentials.

Verified
stdio (local)
OAuth
Go
10 tools
Updated 15 days agoRepo

Read/write Postgres access plus index tuning, EXPLAIN plans, and database health analysis for AI agents.

Verified
stdio (local)
API key
Python
9 tools
Updated 3 months agoRepo

Official Supabase server: manage tables, run SQL, branches, configs and edge functions from your AI client.

Verified
HTTP (remote)
OAuth
TypeScript
12 tools
Updated 1 month agoRepo