# Using Atlas with MongoDB in 2026

> MDB_MCP_READ_ONLY=true limits Atlas to finds and aggregations against MongoDB, so a sampling query can never turn into a write.

MongoDB's official MCP server lets Atlas sample collections, infer the real document shape, and write aggregation pipelines, with a read-only mode that keeps it to finds and aggregations. Add it with atlas mcp add mongodb --env MDB_MCP_CONNECTION_STRING=$MDB_MCP_CONNECTION_STRING --env MDB_MCP_READ_ONLY=true -- npx -y mongodb-mcp-server, and drop MDB_MCP_READ_ONLY only when you deliberately want writes.

## What MongoDB's official MCP server gives Atlas

MongoDB's official MCP server lets Atlas sample collections, infer the real document shape, and write aggregation pipelines. In 2026 that solves the defining problem of working with MongoDB in code: the collection has no declared schema, so the only way to know its shape is to look at the documents.

A relational database tells you what a table looks like. A MongoDB collection does not, because the shape lives in the documents themselves, and it drifts. Fields get added, a field that was a string in 2023 is an object now, and half the documents have an optional key the other half do not. MongoDB's official MCP server lets Atlas sample the collection and see that reality. Everything downstream, the TypeScript interface, the aggregation pipeline, the query, is then grounded in documents that actually exist rather than in the shape someone documented once.

## Adding the MongoDB MCP server to Atlas

Add MongoDB's official server with atlas mcp add mongodb --env MDB_MCP_CONNECTION_STRING=$MDB_MCP_CONNECTION_STRING --env MDB_MCP_READ_ONLY=true -- npx -y mongodb-mcp-server. Both of those 2 environment variables matter in 2026: the connection string points at the deployment, and MDB_MCP_READ_ONLY=true is the guardrail.

The package is mongodb-mcp-server, published by MongoDB, and it runs under npx with no permanent install. MDB_MCP_CONNECTION_STRING carries the connection string, and passing it through the environment rather than an argument keeps the credentials out of the process list. Include MDB_MCP_READ_ONLY=true from the start rather than adding it later, because the safe default is easier to keep than to retrofit. One thing to avoid: the old --connectionString CLI argument is deprecated, so use the env var instead.

## MDB_MCP_READ_ONLY and what it constrains

MDB_MCP_READ_ONLY=true limits Atlas to finds and aggregations against MongoDB. Drop it only when you deliberately want writes. In 2026 this is the flag that lets you leave the MongoDB connection attached to Atlas all day without worrying about what an exploratory query might do to a collection.

Read-only is not a limitation for the workflow this integration is built around, because sampling a collection, inferring its shape, and building an aggregation pipeline are all reads. Finds and aggregations cover the entire loop. Writes are the exception, and treating them as an exception is correct: turning MDB_MCP_READ_ONLY off should be a deliberate act tied to a specific task, not the state your Atlas configuration sits in permanently. Turn it back on when the task is done.

## Connecting Atlas to MongoDB cluster administration

For MongoDB cluster administration rather than data work, swap the connection string for the service account pair MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET. Those 2 environment variables authenticate Atlas against the administrative API in 2026 instead of a single database deployment.

There are two different things a developer might want from MongoDB, and they authenticate differently. Data work, meaning sampling collections and running aggregations, uses MDB_MCP_CONNECTION_STRING and speaks to a deployment. Cluster administration is a different surface, and it uses a service account: MDB_MCP_API_CLIENT_ID paired with MDB_MCP_API_CLIENT_SECRET. Know which one you are configuring before you start, because a connection string will not get you administrative capabilities and a service account will not sample a collection. Most developers using Atlas day to day want the connection string.

## The daily workflow: from a sampled collection to a TypeScript interface

A defining Atlas and MongoDB workflow in 2026 is schema recovery. Ask Atlas to sample a collection, infer the real document shape, and generate the matching TypeScript interface. MongoDB's official MCP server supplies the documents, and Atlas writes the interface into your working tree.

The TypeScript interface for a MongoDB collection is usually a work of fiction: written when the collection was created, never updated, and now missing three fields that production documents have carried for a year. Atlas can fix that with evidence. It samples the collection through MongoDB's official MCP server, sees which fields are consistently present, which are optional, and which have changed type, and writes the interface to match. Because it runs read-only under MDB_MCP_READ_ONLY=true, the sampling cannot alter anything. The output is a diff in your repository that you review like any other change.

## Building an aggregation pipeline with explain output in the diff

Atlas can build a MongoDB aggregation pipeline, run it read-only, and paste the explain output into the diff review. In 2026 that turns a pipeline review from a reading exercise into an evidence-backed one, because you see what the pipeline actually did before you approve it.

Aggregation pipelines are hard to review by eye. A $lookup in the wrong stage or a $match placed after a $group changes the result and the cost, and neither is obvious from reading the JSON. Atlas can run the pipeline read-only against the real collection, which MDB_MCP_READ_ONLY=true guarantees is safe, and bring back the explain output. Having Atlas paste that explain output into the diff review means the pull request contains not just the pipeline but the proof that it does what it claims, at a cost someone actually measured.

## Setup

1. Add MongoDB's official server with atlas mcp add mongodb --env MDB_MCP_CONNECTION_STRING=$MDB_MCP_CONNECTION_STRING --env MDB_MCP_READ_ONLY=true -- npx -y mongodb-mcp-server
2. Keep MDB_MCP_READ_ONLY=true, which limits Atlas to finds and aggregations, and drop it only when you deliberately want writes.
3. Do not use the old --connectionString CLI argument. It is deprecated, so use the MDB_MCP_CONNECTION_STRING env var instead.
4. For cluster administration rather than data work, swap the connection string for the service account pair MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET.
5. Ask Atlas to sample a collection, infer the real document shape, and generate the matching TypeScript interface.
6. Have Atlas build the aggregation pipeline, run it read-only, and paste the explain output into the diff review.

## FAQ

### how to connect atlas to mongodb

Run atlas mcp add mongodb --env MDB_MCP_CONNECTION_STRING=$MDB_MCP_CONNECTION_STRING --env MDB_MCP_READ_ONLY=true -- npx -y mongodb-mcp-server

### how do i make the mongodb mcp server read only

Set MDB_MCP_READ_ONLY=true. It limits Atlas to finds and aggregations. Drop it only when you deliberately want writes.

### mongodb mcp server connectionstring argument deprecated

Correct. The old --connectionString CLI argument is deprecated, so pass MDB_MCP_CONNECTION_STRING as an environment variable instead.

### how do i use the mongodb mcp server for cluster administration

Swap the connection string for the service account pair MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET, which authenticates against the administrative surface.

### can atlas generate a typescript interface from a mongodb collection

Yes. Ask Atlas to sample a collection, infer the real document shape, and generate the matching TypeScript interface, so it reflects real documents rather than stale documentation.

### can atlas write mongodb aggregation pipelines

Yes. Have Atlas build the aggregation pipeline, run it read-only, and paste the explain output into the diff review.

### will atlas write to my mongodb collection

Not with MDB_MCP_READ_ONLY=true set, which keeps Atlas to finds and aggregations. Writes require deliberately removing that variable.

---

Canonical HTML: https://runatlas.sh/resources/integrations/mongodb
Source of truth: aeo_pages row `/resources/integrations/mongodb` (segment: Integrations) (this file is generated from it, never hand-edited).
Licence: Atlas is proprietary with a free core. It is not open source and there is no public source repository.
