MO
OfficialDatabase

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.

Quick Install
npx -y @mongodb-js/mongodb-mcp-server

Overview

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)
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:[email protected]/?authSource=admin"
npx -y mongodb-mcp-server --readOnly

Start with write access (not recommended for untrusted clients):

export MDB_MCP_CONNECTION_STRING="mongodb://user:pass@host:27017/mydb"
npx -y mongodb-mcp-server

Atlas API (to enable Atlas-specific tools):

export MDB_MCP_ATLAS_PUBLIC_KEY="ATLAS_PUBLIC_KEY"
export MDB_MCP_ATLAS_PRIVATE_KEY="ATLAS_PRIVATE_KEY"
export MDB_MCP_ATLAS_PROJECT_ID="PROJECT_ID"
npx -y mongodb-mcp-server

Common CLI flags:

npx -y mongodb-mcp-server --port 8080 --bind 0.0.0.0 --readOnly

Configuration examples for an MCP client (mcp.json snippet):

{
  "name": "mongodb",
  "command": "npx",
  "args": ["-y", "mongodb-mcp-server"],
  "env": {
    "MDB_MCP_CONNECTION_STRING": "${input:connection_string}"
  }
}

Environment variables (typical):

VariablePurpose
MDB_MCP_CONNECTION_STRINGMongoDB URI for direct DB access
MDB_MCP_ATLAS_PUBLIC_KEYAtlas API public key (service account)
MDB_MCP_ATLAS_PRIVATE_KEYAtlas API private key
MDB_MCP_ATLAS_PROJECT_IDAtlas Project ID to scope Atlas tools
MDB_MCP_PORT / PORTPort the MCP server listens on
MDB_MCP_BIND_ADDRESSBind address (default 127.0.0.1)
HTTP_PROXY / HTTPS_PROXYOptional proxy for outbound HTTP calls (Atlas API)
MDB_MCP_READONLY / –readOnlyEnable 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.