MongoDB
MongoDB MCP Server
Official MongoDB MCP server that connects AI coding agents to MongoDB deployments for exploring collections, querying data, and generating code with real schema context.
Last reviewed Feb 28, 2026
What it does
The MongoDB MCP Server connects AI coding agents to MongoDB deployments (Atlas, Community Edition, or Enterprise). Agents can explore collections, run queries, and generate code that matches your actual schema and data. Supports natural-language questions about your data and produces optimized queries and implementation code.
Available tools
| Tool | What it does |
|---|---|
list_databases |
List databases in the deployment |
list_collections |
List collections in a database |
run_query |
Execute a read query and return results |
get_schema |
Infer schema from collection documents |
explain_query |
Explain query plan for a given query |
Exact tool names may vary; check the MongoDB MCP docs for the current API. The server can run in read-only mode with --readOnly.
Setup by tool
Cursor
Create .cursor/mcp.json:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://user:pass@cluster.mongodb.net/mydb"
}
}
}
}
For Atlas API credentials instead of a connection string:
{
"env": {
"MDB_MCP_API_CLIENT_ID": "your-client-id",
"MDB_MCP_API_CLIENT_SECRET": "your-client-secret"
}
}
Claude Code
Add the same configuration to your Claude MCP config. Replace the connection string with your deployment URL. Use --readOnly when agents only need read access.
VS Code / GitHub Copilot
Add the server with the same command, args, and env. Ensure Node.js v20+ is available.
When to use this
- Query generation: Agents write MongoDB queries against real collections and schema
- Schema discovery: Infer schema from documents before generating models or ORM code
- Data exploration: Ask natural-language questions about your data during development
- API development: Generate CRUD endpoints that match your document structure
- Migration planning: Inspect existing collections before schema changes
Security considerations
- Use
--readOnlywhen agents only need to read data - Connect to development or staging clusters, not production
- Connection strings contain credentials; use environment variables, not committed files
- Atlas API credentials should have minimal required scopes
- Consider network restrictions so only authorized hosts can reach the deployment
- Audit queries run by agents; avoid exposing sensitive collections unnecessarily
Compatibility
Related MCP servers
AWS MCP Server
Open source MCP servers from AWS Labs that give AI coding agents access to AWS documentation, best practices, and contextual guidance for building on AWS.
Docker MCP Server
Docker MCP Gateway orchestrates MCP servers in isolated containers, providing secure discovery and execution of Model Context Protocol servers across AI coding tools.
Figma MCP Server
Official Figma MCP server that brings design context, variables, components, and Code Connect data into AI coding sessions for design-to-code workflows.