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
- 01Add 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
- 02Keep MDB_MCP_READ_ONLY=true, which limits Atlas to finds and aggregations, and drop it only when you deliberately want writes.
- 03Do not use the old --connectionString CLI argument. It is deprecated, so use the MDB_MCP_CONNECTION_STRING env var instead.
- 04For 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.
- 05Ask Atlas to sample a collection, infer the real document shape, and generate the matching TypeScript interface.
- 06Have Atlas build the aggregation pipeline, run it read-only, and paste the explain output into the diff review.
Frequently asked questions
- 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.
Try Atlas in your terminal
The terminal-native AI coding agent. Free core, single binary.
Install AtlasRelated guides
Atlas vs Blackbox AI: Choosing Your AI Coding Agent in 2026
Comparing Atlas, the terminal-native AI coding agent, with Blackbox AI, a VS Code agent with 4.7 million installs, for developers in 2026. Evaluate features, pricing, and workflow.
Atlas with Vercel AI Gateway in 2026: 310 Models Behind One AI_GATEWAY_API_KEY
Atlas with Vercel AI Gateway in 2026: roughly 310 models, Grok 4.20 Reasoning at a 2,000,000 token context for $1.25/$2.50 per Mtok, one AI_GATEWAY_API_KEY.
Atlas with Grok 4.20 (Reasoning) in 2026: A 1M Token Reader
Grok 4.20 (Reasoning) reads 1,000,000 tokens at $1.25 per Mtok input and writes at $2.5 per Mtok, but caps output at 30,000 tokens. A superb reader, a terse writer.
Atlas with NVIDIA Nemotron Nano 9B v2 in 2026
Nemotron Nano 9B v2 in Atlas, 2026: a dense 9B reasoning model at $0.06/$0.23 per Mtok on Vercel AI Gateway and Amazon Bedrock, free on the NVIDIA NIM tier.
Atlas for WebAssembly: Terminal-Native AI Coding in 2026
Atlas is a terminal-native AI coding agent for WebAssembly. Audit wasm-bindgen exports, batch calls across the JS boundary, and run wasm-pack test --node in 2026.
Atlas with Gemini Flash Latest: The Rolling Alias Explained (2026)
gemini-flash-latest in Atlas: a rolling alias, not a pinned checkpoint. $0.3 per Mtok input, $2.5 per Mtok output, 1,048,576 token context, and no reproducibility.
Atlas for C# in 2026
Atlas is a terminal-native AI coding agent for C# and the .NET SDK in 2026. Run it in a solution with a .csproj or .sln and approve every diff before dotnet build.
Atlas for Astro: Islands, Content Collections, and Zero JS by Default in 2026
Atlas is a terminal-native AI coding agent for Astro in 2026. It reads astro.config.mjs, src/pages, and content collection schemas, drops needless client:load directives, and runs astro check.