Skip to content

MCP setupDatabases

MongoDB MCP Server

Query MongoDB and Atlas clusters, inspect collections and indexes from your agent with the official server, started in read-only mode.

npx workspacetemplates add mongodb-mcp --tool claude-code

Writes 1 file to your project root

.mcp.jsonmerge into your file15 lines · 261 BFile
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server@latest",
        "--readOnly"
      ],
      "env": {
        "MDB_MCP_CONNECTION_STRING": "${MDB_MCP_CONNECTION_STRING}"
      }
    }
  }
}

What it does

MongoDB's official server lets an agent connect to a cluster, list databases and collections, run queries and aggregations, and look at indexes and schema. With Atlas service account credentials it can also work with projects and clusters.

The setup starts it with the --readOnly flag, which switches off the tools that create, update or delete data. The connection string goes in an environment variable rather than the command line, because arguments can show up in process lists. Drop the flag only for a database you can afford to change.

Example

you › Connect and show how many orders were placed per day over the last week.

agent › 7 rows from an aggregation on orders grouped by day, from 112 orders on Monday to 187 on Friday.

Questions

Can I use Atlas credentials instead?
Yes. Set MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET for an Atlas service account, which also lets it manage Atlas resources.
How do I allow writes?
Remove --readOnly from the args. Do that only against a database with backups.
Where should the connection string live?
In an environment variable, and use a database user with only the roles you need.
  • Convex MCP Server

    MCP setuptypescript

    Free
  • Neon MCP Server

    MCP setupDatabases

    Free
  • PlanetScale MCP Server

    MCP setupDatabases

    Free
  • Prisma MCP Server

    MCP setupDatabases

    Free