MongoDB MCP Server for Atlas & Local Databases
Connect MongoDB Atlas and local databases with an MCP server for secure, scalable Model Context Protocol access and simple deployment.
npx -y @mongodb-js/mongodb-mcp-serverOverview
The MongoDB MCP Server implements the Model Context Protocol (MCP) to expose MongoDB Atlas and self-hosted MongoDB databases to LLM agents and developer tools. It acts as a secure adapter between an LLM-capable client (editors, assistants, integrations) and your database, translating MCP requests into MongoDB operations while enforcing configuration, permissions, and optional read-only behaviour.
This server is useful when you want LLM-based tooling (code assistants, chatbots, query generators) to safely access database metadata, run read-only queries, or interact with Atlas management APIs without embedding direct database credentials into each client. It supports local MongoDB connection strings and Atlas API credentials, is easy to run locally or in cloud deployments, and integrates with MCP-enabled clients like VS Code, Cursor, and web assistants.
Features
- Exposes MongoDB database metadata and operations via MCP
- Support for MongoDB connection strings and MongoDB Atlas API (service account) credentials
- Read-only mode to prevent write operations from LLM clients
- Optional Atlas management tools (clusters, projects, metrics) when Atlas API keys are provided
- Simple single-command start (npx) or container / cloud deployment
- Environment-variable, CLI, and MCP client configuration support
- Proxy and HTTP(S) proxy environment variable support for private networks
- Logs and basic telemetry for debugging and observability
Installation / Configuration
Quick start (read-only example):
# with a MongoDB connection string (recommended to use env vars for secrets)
Start with write access (not recommended for untrusted clients):
Atlas API (to enable Atlas-specific tools):
Common CLI flags:
Configuration examples for an MCP client (mcp.json snippet):
Environment variables (typical):
| Variable | Purpose |
|---|---|
| MDB_MCP_CONNECTION_STRING | MongoDB URI for direct DB access |
| MDB_MCP_ATLAS_PUBLIC_KEY | Atlas API public key (service account) |
| MDB_MCP_ATLAS_PRIVATE_KEY | Atlas API private key |
| MDB_MCP_ATLAS_PROJECT_ID | Atlas Project ID to scope Atlas tools |
| MDB_MCP_PORT / PORT | Port the MCP server listens on |
| MDB_MCP_BIND_ADDRESS | Bind address (default 127.0.0.1) |
| HTTP_PROXY / HTTPS_PROXY | Optional proxy for outbound HTTP calls (Atlas API) |
| MDB_MCP_READONLY / –readOnly | Enable read-only behavior to block writes |
Note: Secrets should be supplied via environment variables or secret stores; avoid embedding credentials into shared MCP client configs.
Available Tools / Resources
When configured, the server exposes a set of MCP tools and resources. Examples include:
- Database tools:
- List databases and collections
- Schema inference for collections
- Explain plans and aggregation execution (subject to read/write mode)
- Index listing and basic index advice
- Atlas tools (requires Atlas API keys):
- Cluster and project metadata
- Deployment/cluster lists and statuses
- Metrics and logs access (read-only)
- User and role listings (service-account scoped)
- Assistant utilities:
- Query builders that return executable MongoDB queries
- Context providers that present sample documents or schema snippets
- Safety filters to avoid destructive operations when read-only enabled
Use Cases
- Integrate MongoDB access into an LLM assistant inside VS Code or Cursor so the assistant can suggest queries, inspect schemas, or generate aggregation pipelines without exposing raw credentials to the client.
- Provide a safe playground for data analysts: run the MCP server in read-only mode so agents can explore data and generate insights without accidental writes.
- Centralized control for multi-tool environments: run the server in a cloud or private network and allow multiple MCP-enabled clients to share a single, audited connection to Atlas or self-hosted databases.
- CI/test automation: spin up a local MCP server pointing at test databases to let automated agents perform queries and structure checks.
Deployment Notes
- Running in containers or cloud services: pass secrets via secure environment variables or secret stores. Keep the server behind an internal network or require client authentication if exposing publicly.
- Proxy support: standard HTTP_PROXY/HTTPS_PROXY environment variables are respected for Atlas API calls.
- Azure / other clouds: configure the app service or container with the relevant env vars and optional port binding.
Contributing & Resources
Source and issues: https://github.com/mongodb-js/mongodb-mcp-server
If you encounter bugs or want to add features, open an issue or submit a pull request in the repository. Contributions are welcome, especially around richer Atlas tool coverage, better schema extraction, and more granular permission controls.