Omniscio

OmniscioGuidesMongoDB MCP server

Giving Claude Code read-only access to MongoDB

MongoDB publishes its own MCP server, and the safe configuration is the one its documentation shows first. MCP is the Model Context Protocol, the standard that lets Claude Code call an outside service's tools — here, queries against your own collections.

There are two servers with the MongoDB name — a local one that runs on your machine and a hosted Atlas one — and the credential stories are different enough that mixing them up is the usual source of a setup that refuses to connect.

Sources read November 25, 2026. By the Omniscio team. Updated .

Which MongoDB server

This page covers the local one, published by MongoDB as the npm package mongodb-mcp-server and run with npx -y mongodb-mcp-server@latest. It runs on your machine and Claude Code talks to it over stdio, the standard input and output every local MCP server uses. It connects to any deployment — a database on your machine, a self-managed cluster, or an Atlas cluster — with the credentials you give it.

The Atlas-managed remote server is the other one. It is OAuth-based and MongoDB recommends reaching it through its own agent plugin rather than by hand. This page covers the local server and notes where the two differ, because the difference is where people get stuck.

What Claude Code can do with it

The database tools are the ones you would expect from a shell: find, aggregate, count, explain, list-databases, list-collections, collection-schema, collection-indexes, db-stats and mongodb-logs, alongside the write tools the safe configuration leaves out.

The Atlas tools are a separate group — clusters, projects, database users, performance advisor, alerts — for MongoDB's hosted service, Atlas. MongoDB is explicit that they are available only when Atlas credentials are configured. A server that answers database questions and says nothing about your clusters is usually this, not a broken install.

There is also an assistant tool group, which searches MongoDB's own knowledge base of documentation and curated guidance rather than your data.

The command

The connection string — the mongodb://user:password@host:port/database line every MongoDB client uses — goes in as an environment variable, the package runs through npx, and --readOnly comes after the double dash because it is the server's own flag:

claude mcp add mongodb \
  --env MDB_MCP_CONNECTION_STRING=mongodb://user:password@localhost:27017/mydb \
  -- npx -y mongodb-mcp-server@latest --readOnly

Order matters. --env keeps taking KEY=value pairs until it reaches the double dash, so the server name has to come before --env; put it after and Claude Code tries to read the name as another environment variable and refuses the command.

If you would rather not put the string on the command line at all, MongoDB ships a setup command that walks through the connection string and the Atlas credentials interactively: npx -y mongodb-mcp-server@latest setup.

If you are writing .mcp.json instead of running a command, the same setting is the environment variable MDB_MCP_READ_ONLY, set to true.

The .mcp.json equivalent

This is MongoDB's own configuration block, unchanged:

{
  "mcpServers": {
    "MongoDB": {
      "command": "npx",
      "args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
      "env": {
        "MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
      }
    }
  }
}

The --readOnly in args is what keeps the write tools out of the session. MongoDB's note says every example below that point includes it, so this block is safe as printed — but the flag is not applied for you, and two later configuration examples in the same README leave it out.

A .mcp.json at the repository root is project scope, so a literal connection string with a password in it is read by everyone who clones the repository. Keep a real credential at local or user scope, and use the file for a database the team shares.

Which scope to use

Local is the default: the entry lives in your own configuration and loads only in the project where you added it. --scope project writes .mcp.json at the repository root and shares it, and --scope user makes it available in every project.

Because the connection string is fixed when the server starts, user scope has a specific trap: one database's connection string is then live in every project you open, and a question asked in the wrong window is answered from the wrong database. Local scope keeps that decision per project, which is usually what you want when the string carries a real credential.

The auth step

The server has no sign-in step of its own: the connection string is the credential, so the database user and its roles are the entire permission model. Create a user that can read the databases Claude should see and nothing else, and treat read-only mode as the second lock rather than a substitute for the grants. MongoDB's own first example still uses MDB_MCP_CONNECTION_STRING, which is why this page does, though a note now marks it deprecated in favour of a preconfigured entry in MDB_MCP_CONNECTION_STRINGS.

Without a connection string the server still starts. It has no connection yet, and you call its connect tool with a connection string before any data tool will work — which is what MongoDB means when it calls the variable optional.

The Atlas tools need a different credential: a service account client ID and secret, as MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET. MongoDB's security note is to keep both in the environment rather than in command-line arguments, where they are visible in a process list.

The hosted Atlas server does not accept those credentials over HTTP at all. MongoDB states that you cannot authenticate to the remote server with a static API key, so the choice is a client that can run the OAuth flow or the mongodb-atlas-mcp-remote package over stdio.

Confirm it connected

claude mcp list
claude mcp get mongodb

The list prints a health status beside each server, such as ✔ Connected, ! Needs authentication or ✘ Failed to connect, and appends the failure detail when a connection fails. A local server has nothing to sign in to, so a broken start reads ✘ Failed to connect rather than "needs authentication". A project-scope .mcp.json server reads ⏸ Pending approval until you approve it in an interactive session.

Inside a session, /mcp shows each connected server with its tool count, which is where you check that no create, update or delete tool appears, and the server's own list-connections tool prints the connections it is holding. Then ask Claude to list your databases — a question with an answer you can check in a shell.

The failure people hit

The first is a write that never happens — not a failure so much as the flag working. Read-only mode does not deny the write at call time; the tools that create, update and delete are never registered, so from inside a session the server has fewer tools than the documentation describes.

The second is the confirmation prompt, which has two surprises. MongoDB asks the client to show you a confirmation before a named list of destructive tools runs — dropping a database or a collection, deleting many documents, dropping an index, and the Atlas tools that create users or tear down streams — plus any aggregation that writes with a $out or $merge stage. That request is called elicitation. A client that cannot show it runs the tool without asking. A client that advertises support but has nobody to answer, such as an unattended run, is treated as a decline: the tool reports that the execution was not confirmed, nothing changes, and the run may still finish successfully.

The third is an Atlas credential sent to the hosted server as a static API key, which MongoDB says cannot work over HTTP. If the remote server asks for an interactive sign-in, it is behaving as documented.

The general messages are collected in the MCP errors guide, and the flags and scopes in Add an MCP server to Claude Code.

Sources

Every line on this page rests on one of these. The date beside each one is the day we read it.

  • mongodb-js/mongodb-mcp-server README, for the package and the npx form, the --readOnly note and what read-only mode registers, the connection variables, the setup command, the database and Atlas tool lists, the Atlas credential requirement, the static-key rule for the remote server, the confirmation behaviour and the security note. Read November 25, 2026.
  • Anthropic: Connect Claude Code to tools via MCP, for the command shape, the --env pair rule, the double dash, the scope table and the health statuses. Read November 25, 2026.

Common questions

What is the command to add the MongoDB MCP server to Claude Code?

claude mcp add mongodb --env MDB_MCP_CONNECTION_STRING=mongodb://localhost:27017/mydb -- npx -y mongodb-mcp-server@latest --readOnly. The package, the flag and the variable are all from MongoDB's own README.

Why does Claude say it cannot change any data?

Read-only mode does not block writes, it never registers the tools that write. Every setup example in MongoDB's manual section includes --readOnly, so a copied command leaves create, update and delete out of the session entirely.

Can I use an Atlas API key with the hosted MongoDB MCP server?

Not over HTTP. MongoDB states you cannot authenticate to the remote server with a static API key, so you either use a client that supports the OAuth flow or the mongodb-atlas-mcp-remote stdio package with service account credentials.

What happens without a connection string?

The server still starts. You then have to call its connect tool before it can reach any data, which is why MongoDB calls the connection string optional rather than required.

Do I have to confirm every write?

No. MongoDB gates a named list of destructive tools — dropping a database or collection, deleting many documents, dropping an index, and four Atlas tools — plus any aggregation with a write stage. A client without elicitation support runs them without asking; one that supports it but has no user to answer is treated as a decline.

Every session, one window

Omniscio runs several agent sessions side by side in one window, each with its own context and its own diff view. Any model, any harness — Claude Code, Codex, OpenCode, Devin, Pi, and Hermes all supported.