🗄️

MongoDB

Connect to MongoDB databases and Atlas clusters for querying.

Category: Database
Difficulty: Medium

Quick Configuration

Choose the setup that matches your environment.

Before You Start

  • Confirm you have the account, endpoint, or API key required for MongoDB.
  • Start with minimum scopes and read-only access where possible.
  • Keep secrets in environment variables instead of hardcoding them in JSON.
Last verified: 2026-06-13
Environment: Node.js 18+, mongodb-mcp-server over stdio (read-only mode)
Install command: npx -y mongodb-mcp-server --readOnly

Local config

JSON
Local config json
{
  "mongodb": {
    "command": "npx",
    "args": ["-y", "mongodb-mcp-server", "--readOnly"],
    "env": {
      "MDB_MCP_CONNECTION_STRING": "mongodb+srv://USER:PASSWORD@cluster.mongodb.net/"
    }
  }
}

After copying

Check the MongoDB JSON before running it in OpenClaw, then verify the server with a real prompt.

Verify prompt

List the databases and collections, and describe the schema of the largest collection.

Expected success output

You should see databases, collections, and an inferred schema, returned read-only.

Common Pitfalls & Fixes

  • ⚠️ Watch out: Connection string format, Atlas network access, and schema discovery.
  • 🔑 Always store API keys in environment variables, never hardcode them in JSON.
  • 🛡️ Start with read-only scopes if available to verify connection safely.

Security checklist

  • Keep MDB_MCP_CONNECTION_STRING in env and use a least-privilege, read-only DB user.
  • Keep --readOnly enabled for production clusters.

Common errors

Error Cause Fix
Authentication failed The credentials in MDB_MCP_CONNECTION_STRING are wrong. Check the user/password and the database user roles.
Connection timed out Atlas IP access list blocks your address. Add your IP under Atlas Network Access, then retry.
Write blocked --readOnly blocks mutations by design. Remove --readOnly only in a safe, non-production environment.

Example Prompts

Once connected, try these prompts to test capabilities:

  • List all collections in the database and their document counts.
  • Find documents matching a filter and return the first 10 results.
  • Show database indexes and their purposes.

Verification Checklist

  • Run 1-2 real prompts to confirm MongoDB returns usable data.
  • Check that error messages are clear enough for troubleshooting.
  • Document the required scopes, dependencies, and env vars for future reuse.