Back to Skill Directory

MCP Server

Document DatabaseAtlas Vector SearchApache 2.0

MongoDB MCP Server

by MongoDB · mongodb-js/mongodb-mcp-server

MongoDB MCP Server gives AI agents structured access to MongoDB and MongoDB Atlas through the Model Context Protocol. Claude Code or Cursor can list collections, inspect schemas, run find and aggregate queries, and — on Atlas — perform Vector Search, all without you writing a single line of driver code.

With a read-only connection string and careful tool scoping, the MCP server becomes a safe analytics and debugging surface. The agent can answer ad-hoc data questions, diagnose production issues, or build RAG pipelines over embedded document fields — all from inside your editor.

10+
Tools Exposed
find, aggregate, vector
<3min
Setup
npx + URI
Self/Atlas
Hosting
local or managed
Apache 2.0
License
open source

Quick Install

claude mcp add mongodb -- npx -y mongodb-mcp-server

Key Features

Find & Project

Run filtered find queries with projection, sort, skip, and limit. Agent can page through collections without loading full documents.

Aggregate Pipelines

Execute full aggregation pipelines ($match, $group, $lookup, $project, $facet) for analytics, joins, and summaries directly from the agent.

Schema Inspection

Inspect collection schemas with field samples and types. Lets the agent understand an unfamiliar dataset before querying it.

Atlas Vector Search

On Atlas, run $vectorSearch with a query embedding and index name to perform top-K semantic retrieval — turning MongoDB into an embedded vector DB.

Read-Only Mode

Toggle a read-only flag to block insert/update/delete tools entirely. Ideal for production data exploration.

Atlas Admin API

Optionally connect the Atlas admin API to list clusters, projects, and users — so the agent can answer infra questions alongside data questions.

Execution Brief

Use this page as a rollout checklist, not just reference text.

Suggest update

Tool Mapping Lens

Organize Tools by Workflow Phase

Catalog-oriented pages work best when users can map discovery, evaluation, and rollout in a clear path instead of reading an undifferentiated list.

  • Define the job-to-be-done first
  • Group tools by stage
  • Prioritize by adoption friction

Actionable Utility Module

Skill Implementation Board

Use this board for MongoDB MCP Server before rollout. Capture inputs, apply one decision rule, execute the checklist, and log outcome.

Input: Objective

Deliver one measurable improvement with mongodb mcp server claude code atlas vector search aggregate pipeline

Input: Baseline Window

20-30 minutes

Input: Fallback Window

8-12 minutes

Decision TriggerActionExpected Output
Input: one workflow objective and release owner are definedRun preview execution with fixed acceptance criteria.Go or hold decision backed by repeatable evidence.
Input: output quality below baseline or retries increaseLimit scope, isolate root issue, and rerun controlled test.One confirmed correction path before wider rollout.
Input: checks pass for two consecutive replay windowsPromote to broader traffic with fallback path active.Stable rollout with low operational surprise.

Execution Steps

  1. Record objective, owner, and stop condition.
  2. Execute one controlled preview run.
  3. Measure quality, latency, and correction burden.
  4. Promote only when pass criteria are stable.

Output Template

tool=mongodb mcp server claude code atlas vector search aggregate pipeline
objective=
preview_result=pass|fail
primary_metric=
next_step=rollout|patch|hold

What Is MongoDB MCP Server?

MongoDB MCP Server is a Model Context Protocol bridge that exposes a MongoDB cluster — self-hosted or Atlas — to AI coding assistants. It surfaces the core read and aggregation operations as MCP tools (find, aggregate, count, distinct, list collections, sample schema), so an agent can interact with document data through a safe, typed interface.

For Atlas users, the MCP server also exposes Vector Search, giving the agent a single endpoint for semantic retrieval over embedded fields. That means a team already using MongoDB for primary storage can run RAG workloads without standing up a separate vector database — the embeddings live right next to the source documents.

From a developer-experience perspective, the server shines when debugging and analytics collide. Instead of switching to a MongoDB GUI, constructing a pipeline by hand, and copying results back, you ask the agent: "aggregate orders by day for the last week where status is shipped and compute median processing time." The agent translates intent into a $group/$bucket pipeline and returns the answer inline.

The security model is delegated to MongoDB itself. Create a dedicated MCP user with least-privilege permissions — read-only access to specific databases is the typical recommendation. Combine that with the server's read-only mode flag for defense in depth, and the risk surface of letting an agent query your DB shrinks to near zero.

How to Calculate Better Results with mongodb mcp server claude code atlas vector search aggregate pipeline

Create a dedicated MongoDB user for the MCP server. Grant readAnyDatabase or scope it to specific databases. Copy the connection string — for Atlas this looks like mongodb+srv://user:[email protected]/.

Install the server: claude mcp add mongodb -- npx -y mongodb-mcp-server. Set MDB_MCP_CONNECTION_STRING to the URI. Optionally set MDB_MCP_READ_ONLY=true to disable mutation tools at the server layer.

Verify schema discovery. Ask the agent to "list collections in the analytics database and sample the schema of the orders collection." If it returns field types and example values, the connection is healthy.

Kick the tires with an aggregation. Ask: "What are the top 5 product categories by revenue for last month?" The agent should compose a $match + $group + $sort + $limit pipeline and return the answer without you seeing the query at all.

Treat this page as a decision map. Build a shortlist fast, then run a focused second pass for security, ownership, and operational fit.

When a team keeps one shared selection rubric, tool adoption speeds up because evaluators stop debating criteria every time a new option appears.

Worked Examples

Ad-hoc analytics inside the editor

  1. You have a production MongoDB Atlas cluster with an orders collection
  2. You grant the MCP server a read-only user scoped to the analytics DB
  3. During a standup you ask Claude Code "what was yesterday's conversion rate by traffic source?"
  4. Agent inspects the orders and sessions schemas via sample_schema
  5. Composes a $lookup + $group pipeline joining sessions to orders, grouping by source
  6. Returns a clean table with source, sessions, orders, and conversion rate

Outcome: Sub-minute ad-hoc analytics without leaving your editor, and without giving the agent write access to production data.

RAG over product documentation stored in MongoDB Atlas

  1. Your product docs live in Atlas with an embeddings field and a vector search index
  2. User asks the agent: "how do I enable webhook retries?"
  3. Agent computes an embedding of the query via OpenAI
  4. Calls mongodb_vector_search with the index name and top_k=5
  5. Receives the five most relevant doc chunks with scores
  6. Composes a grounded answer with citations back to the source doc IDs

Outcome: A production RAG pipeline that reuses your existing Atlas cluster for both primary storage and semantic search — one operational footprint instead of two.

Frequently Asked Questions

What is the MongoDB MCP Server?

MongoDB MCP Server is a Model Context Protocol integration that exposes a MongoDB or MongoDB Atlas deployment to AI coding assistants. It provides MCP tools for listing databases and collections, running find and aggregate queries, inspecting schemas, and — when using Atlas — performing Vector Search over embedded fields. Claude Code, Cursor, and other MCP clients can then read and analyze MongoDB data without any custom driver code.

How do I set up MongoDB MCP?

Install with claude mcp add mongodb -- npx -y mongodb-mcp-server. Set MDB_MCP_CONNECTION_STRING to a standard MongoDB URI (mongodb://... or mongodb+srv://... for Atlas). For read-only safety, use a connection string with a restricted user. Restart your MCP client and the mongodb_* tools appear in the agent's toolbox.

Is it safe to let an agent run MongoDB queries?

Safety depends on the database user credentials, not the MCP server. Create a read-only MongoDB user for the MCP connection string. The server also supports a read-only mode flag that blocks insert, update, and delete operations at the tool layer. For production data, we strongly recommend using a replica-set secondary or an anonymized staging cluster.

Does it support MongoDB Atlas Vector Search?

Yes. If your collection has a vector index, the MCP server exposes a vector_search tool that runs $vectorSearch aggregation under the hood. Provide the query embedding and index name; the server returns top-K matching documents with scores. This makes MongoDB a credible alternative to dedicated vector DBs when you already use Atlas.

Can the agent run aggregation pipelines?

Yes. The mongodb_aggregate tool accepts a full pipeline array ($match, $group, $lookup, $project, etc.). This is the most powerful operation exposed — it lets the agent run analytical queries, join across collections, and compute summaries without exporting data. Pair it with read-only credentials for a safe analytics sandbox.

MongoDB MCP vs Postgres MCP — which should I pick?

Pick MongoDB MCP if your data is document-shaped (nested JSON, flexible schemas, event logs) or you are already on Atlas. Pick Postgres MCP if your data is relational, you need strong transactional guarantees, or you want SQL joins. Both can coexist — many agent workflows use Postgres for structured business data and MongoDB for documents or logs, with the agent orchestrating both through their respective MCP servers.

Missing a better tool match?

Send the exact workflow you are solving and we will prioritize a new comparison or rollout guide.