Overview
Query and manage MongoDB databases directly from AI agents.
Setup
Run with npx:
npx -y @modelcontextprotocol/server-mongodb mongodb://localhost:27017Configuration
MongoDB connection string as argumentDocumentation
MongoDB MCP
Overview
MongoDB MCP provides direct access to MongoDB databases, enabling AI agents to query, analyze, and manage MongoDB collections. Ideal for database debugging, data exploration, and building MongoDB-powered features.
Features
- CRUD Operations: Insert, find, update, and delete documents
- Aggregation Pipeline: Run complex aggregation queries
- Schema Analysis: Explore collection structures and indexes
- Database Management: List databases, collections, and documents
- Query Building: Natural language to MongoDB query conversion
Installation
npx -y @modelcontextprotocol/server-mongodb mongodb://localhost:27017
Configuration
Add to your Claude Desktop config:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-mongodb", "mongodb://localhost:27017"]
}
}
}
For MongoDB Atlas:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-mongodb", "mongodb+srv://username:password@cluster.mongodb.net/"]
}
}
}
Available Tools
| Tool | Description |
|---|---|
list_databases | List all accessible databases |
list_collections | List collections in a database |
find | Query documents with filter |
insert_one | Insert a single document |
insert_many | Insert multiple documents |
update_one | Update a single document |
update_many | Update multiple documents |
delete_one | Delete a single document |
delete_many | Delete multiple documents |
aggregate | Run aggregation pipeline |
count_documents | Count documents matching filter |
distinct | Get distinct values for a field |
Usage Examples
Query Documents
Find all users where age > 25 and status = "active"
Find documents in "products" collection where price < 100
Aggregation
Aggregate "orders" collection:
- Group by customer_id
- Sum total amount
- Sort by total descending
- Limit to top 10
Update Documents
Update user "user_123" to set status = "premium"
Increment "views" field by 1 for all posts in "posts" collection
Schema Exploration
List all collections in "myapp" database
Show sample documents from "users" collection
Claude Desktop Setup
- Install the MCP server with your MongoDB connection string
- Add configuration to
claude_desktop_config.json - Restart Claude Desktop
- The MongoDB tool will appear in your available tools
Pros
- ✅ Direct MongoDB query interface
- ✅ Full CRUD and aggregation support
- ✅ Works with local and Atlas MongoDB
- ✅ Natural language query building
- ✅ Great for data exploration
Cons
- ❌ Requires MongoDB instance to be running
- ❌ Connection string must be managed carefully
- ❌ No visual query builder
- ❌ Complex aggregations may need manual construction
