MongoDB MCP Server
MongoDB MCP servers enable AI models to interact with MongoDB databases and MongoDB Atlas, providing capabilities for document operations, aggregation pipelines, cloud database management, and natural language queries.
Overview
The MongoDB MCP Server is the official Model Context Protocol server from MongoDB that enables AI assistants to interact directly with MongoDB databases and MongoDB Atlas. It provides natural language access to database operations, schema inspection, and cloud resource management for both local and Atlas deployments.
Official Server:
Developed and maintained by MongoDB
Key Features
MongoDB Atlas Integration
Manage Atlas clusters, projects, users, and network access directly through AI
Document Operations
Query, insert, update, and delete documents using natural language commands
Schema Intelligence
Automatic schema inspection and pattern discovery across collections
Read-Only Mode
Built-in read-only mode for safe data exploration and analysis
Available Tools
Quick Reference
| Tool | Purpose | Category |
|---|---|---|
connect | Connect to MongoDB instance | Connection |
find | Query documents in collection | Read |
aggregate | Run aggregation pipelines | Read |
count | Count documents in collection | Read |
insert-one | Insert single document | Write |
insert-many | Insert multiple documents | Write |
update-one | Update single document | Write |
update-many | Update multiple documents | Write |
delete-one | Delete single document | Write |
delete-many | Delete multiple documents | Write |
create-index | Create collection index | Schema |
list-databases | List all databases | Schema |
list-collections | List collections in database | Schema |
collection-schema | Describe collection schema | Schema |
collection-indexes | List collection indexes | Schema |
collection-storage-size | Get collection size in MB | Stats |
db-stats | Get database statistics | Stats |
rename-collection | Rename a collection | Admin |
drop-collection | Remove a collection | Admin |
drop-database | Remove a database | Admin |
Detailed Usage
connect▶
Establish connection to a MongoDB instance using a connection string.
use_mcp_tool({
server_name: "mongodb",
tool_name: "connect",
arguments: {
connectionString: "mongodb://localhost:27017/myDatabase"
}
});
Supports MongoDB Atlas, Community Edition, and Enterprise Advanced.
find▶
Query documents from a collection with optional filters and projections.
use_mcp_tool({
server_name: "mongodb",
tool_name: "find",
arguments: {
database: "myDatabase",
collection: "users",
filter: { status: "active" },
limit: 10
}
});
aggregate▶
Execute aggregation pipelines for complex data transformations and analytics.
use_mcp_tool({
server_name: "mongodb",
tool_name: "aggregate",
arguments: {
database: "myDatabase",
collection: "orders",
pipeline: [
{ $match: { status: "completed" } },
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } },
{ $sort: { total: -1 } }
]
}
});
count▶
Count documents in a collection matching optional filter criteria.
use_mcp_tool({
server_name: "mongodb",
tool_name: "count",
arguments: {
database: "myDatabase",
collection: "users",
filter: { status: "active" }
}
});
insert-one▶
Insert a single document into a collection.
use_mcp_tool({
server_name: "mongodb",
tool_name: "insert-one",
arguments: {
database: "myDatabase",
collection: "users",
document: {
name: "John Doe",
email: "[email protected]",
status: "active"
}
}
});
Disabled when using --readOnly flag.
insert-many▶
Insert multiple documents into a collection in a single operation.
use_mcp_tool({
server_name: "mongodb",
tool_name: "insert-many",
arguments: {
database: "myDatabase",
collection: "users",
documents: [
{ name: "Alice", email: "[email protected]" },
{ name: "Bob", email: "[email protected]" }
]
}
});
update-one▶
Update a single document matching the filter criteria.
use_mcp_tool({
server_name: "mongodb",
tool_name: "update-one",
arguments: {
database: "myDatabase",
collection: "users",
filter: { email: "[email protected]" },
update: { $set: { status: "inactive" } }
}
});
create-index▶
Create an index on a collection to improve query performance.
use_mcp_tool({
server_name: "mongodb",
tool_name: "create-index",
arguments: {
database: "myDatabase",
collection: "users",
keys: { email: 1 },
options: { unique: true }
}
});
list-databases▶
List all databases accessible through the current connection.
use_mcp_tool({
server_name: "mongodb",
tool_name: "list-databases",
arguments: {}
});
list-collections▶
List all collections in a specified database.
use_mcp_tool({
server_name: "mongodb",
tool_name: "list-collections",
arguments: {
database: "myDatabase"
}
});
collection-schema▶
Inspect the schema structure of a collection by analyzing document samples.
use_mcp_tool({
server_name: "mongodb",
tool_name: "collection-schema",
arguments: {
database: "myDatabase",
collection: "users"
}
});
Useful for understanding data patterns and field types in schema-less documents.
collection-indexes▶
List all indexes defined on a collection.
use_mcp_tool({
server_name: "mongodb",
tool_name: "collection-indexes",
arguments: {
database: "myDatabase",
collection: "users"
}
});
MongoDB Atlas Tools
The server also provides tools for managing MongoDB Atlas resources:
- Organization & Project Management: List and create Atlas organizations and projects
- Cluster Operations: Create free tier clusters, list clusters across projects
- User Management: Create database users with specific roles
- Network Security: Manage IP access lists
- Monitoring: Access alerts and performance advisories
- Atlas Local: Deploy and manage local Atlas development environments
Installation
Prerequisites
- Node.js 20.19.0+, v22.12.0+, or v23+
- MongoDB connection string (local or Atlas)
Configuration
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server@latest",
"--readOnly"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
}
}
}
}
Read-Only Mode:
The --readOnly flag is recommended for safe data exploration. Remove it to enable write operations.
Atlas Connection String Example
{
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:[email protected]/myDatabase"
}
}
Common Use Cases
Data Analysis
Explore data patterns and schemas using natural language:
"Show me the schema of the users collection and find the most common user types"
Query Generation
Generate complex aggregation pipelines:
"Create an aggregation to group orders by customer and calculate total spending,
sorted by highest spenders first"
Database Administration
Manage indexes and performance:
"Create a unique index on the email field in the users collection,
then show all indexes for that collection"
Additional Deployment Options
Docker
Run the server in a container without local Node.js:
docker run -e MDB_MCP_CONNECTION_STRING="mongodb://..." mongodb-mcp-server
HTTP Server
Deploy as an HTTP service:
npx mongodb-mcp-server --transport http --port 3000
HTTP Security:
When using HTTP transport, implement authentication, TLS encryption, and firewall protection. Never expose directly to the internet.
Sources
Related Articles
Development Tools & DevOps MCP Servers
Streamline your development workflow with our Development Tools & DevOps integrations. Connect with version control systems, CI/CD pipelines, container platforms, and more to build, test, and deploy your AI applications faster and more reliably.
Gaming and Entertainment MCP Servers
The Gaming & Entertainment category provides integration with gaming platforms and entertainment systems, enabling interactive gaming experiences and virtual entertainment management.
Thirdweb MCP Server
Thirdweb MCP servers enable AI agents to interact with EVM blockchains via thirdweb services, supporting multi-chain data querying, wallet and contract operations, autonomous execution, and both hosted and self-hosted deployment options.