
MCP MongoDB Server
Let LLMs query, aggregate, and write to MongoDB with schema inference and read-only protection.
Add to your client
Copy the config for your MCP client and paste it into its config file.
npx -y mcp-mongo-server mongodb://localhost:27017/databasePaste 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)
queryExecute MongoDB queries with filter, projection, and limit options, plus an optional explain plan (e.g. executionStats).
aggregateRun MongoDB aggregation pipelines, with an optional explain plan (e.g. queryPlanner).
countCount documents in a collection that match a query.
updateModify documents matching a filter, with upsert and multi options (disabled in read-only mode).
insertInsert one or more new documents into a collection (disabled in read-only mode).
createIndexCreate one or more indexes on a collection, including unique and named indexes (disabled in read-only mode).
serverInfoGet 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.
Read/write Postgres access plus index tuning, EXPLAIN plans, and database health analysis for AI agents.
Official Supabase server: manage tables, run SQL, branches, configs and edge functions from your AI client.
Compare MCP MongoDB Server with: