MongoDB
An MCP server for MongoDB that lets AI assistants inspect, query, aggregate, and optionally modify database data and indexes.
List collections and get MongoDB server/storage-engine info; infer schemas from sampled documents.
Query, count, and aggregate data with filters, projections, limits, hints, collation, timeouts, and explain plans.
Handle ObjectIds with configurable auto/none/force conversion and convert timestamps/date strings to UTC/GMT/ISO.
Insert documents, update documents (single/multi/upsert), and create one or more indexes when writes are enabled.
Enforce read-only mode, block cross-database aggregation stages and server-side JavaScript by default, and support stdio or authenticated HTTP transports.
Provides access to MongoDB databases, allowing LLMs to inspect collection schemas and execute MongoDB operations like queries, aggregations, updates, inserts, and creating indexes
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MongoDB show me the schema for the users collection"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP MongoDB Server
A Model Context Protocol (MCP) server that lets AI assistants work with your MongoDB databases. It exposes your collections, infers their schemas, and runs queries, aggregations, and writes through a standard interface — so tools like Claude Desktop and Cursor can read and reason about your data.
Demo

Related MCP server: MongoDB MCP Server for LLMs
Why use it
Talk to your database in plain language — the assistant discovers your collections and their shape automatically.
Read-only mode — restrict write operations globally or per connection.
Works everywhere — connects to standalone, replica set, sharded, and Atlas deployments, over plain or TLS connections.
Key Features
Read-Only Mode — blocks every write path (insert, update, index creation, and aggregation stages like
$out/$mergethat could modify data).Smart ObjectId Handling — configurable
auto/none/forceconversion of 24-character hex strings to ObjectIds.Schema Inference — automatic collection schema detection from document samples.
Query & Aggregation — full query and aggregation pipeline support, with optional
explainplans.Write Operations — insert, update, and index creation (when read-only mode is off).
Time Conversion — a
convertTimehelper turns Unix timestamps and date strings into UTC/GMT/ISO, so date queries stay unambiguous across timezones.Progress & Cancellation — long operations report progress and can be cancelled mid-flight.
Two Transports — run locally over stdio, or expose an HTTP endpoint for remote access.
Requirements
Node.js 20 or newer
Quick Start
Point the server at your database — no install step needed:
npx -y mcp-mongo-server mongodb://localhost:27017/mydatabaseExplore safely, without any chance of changing data:
npx -y mcp-mongo-server mongodb://localhost:27017/mydatabase --read-onlyUsage
Local (stdio)
This is the default, used by Claude Desktop, Cursor, and other local clients:
npx -y mcp-mongo-server "mongodb://user:pass@localhost:27017/mydatabase"Remote (HTTP)
Expose an HTTP endpoint at /mcp for remote or multi-client access:
npx -y mcp-mongo-server "mongodb://user:pass@localhost:27017/mydatabase" --transport http --port 3001By default, only requests without a browser Origin (CLIs, IDEs) and requests
from localhost are accepted; everything else is rejected with 403 to guard
against DNS-rebinding attacks. Allow specific browser origins with
--allowed-origins:
npx -y mcp-mongo-server "mongodb://..." --transport http --port 3001 --allowed-origins "https://app.example.com"Options
Flag | Description |
| Block all write operations |
| Allow aggregation |
| Allow server-side JavaScript operators |
|
|
| HTTP port (default |
| Comma-separated browser origins to allow in HTTP mode |
| Max HTTP request body size (default |
| Require |
Environment Variables
Variable | Description |
| MongoDB connection URI (alternative to the argument) |
| JSON object of named MongoDB connections and their database permissions |
| Optional document cap for |
| Optional UTF-8 byte cap for the compact JSON results array, minimum 2 |
| Optional MongoDB operation timeout in milliseconds for |
| Enable read-only mode ( |
| Allow cross-database aggregation stages ( |
| Allow server-side JavaScript operators ( |
| HTTP port |
| Comma-separated browser origins to allow in HTTP mode |
| Max HTTP request body size (default |
| Bearer token required to access the HTTP endpoint |
Named connections
Set MCP_MONGODB_CONNECTIONS to a JSON string. This MCP client configuration
uses a local build and the two Docker test databases.
{
"mcpServers": {
"mongodb": {
"command": "node",
"args": [
"/absolute/path/to/mcp-mongo-server/build/index.js"
],
"env": {
"MCP_MONGODB_CONNECTIONS": "{\"default\":{\"uri\":\"mongodb://127.0.0.1:37017/mcp_test\"},\"analytics\":{\"uri\":\"mongodb://127.0.0.1:37018/mcp_test?directConnection=true\",\"databases\":[\"mcp_test\",\"mcp_test_secondary\"],\"readOnly\":true}}"
}
}
}
}Discover targets with
listConnectionsandlistDatabases. PassconnectionIdanddatabaseto database tools and the collection analysis prompt. Omitted selectors use thedefaultconnection and its URI database.Omit
databasesto allow only the URI database. If supplied, the list must include the URI database. Global read-only mode applies to every connection.Write tools appear in tool discovery when at least one connection is writable. Use
listConnectionsto choose a writable target.A positional URI or
MCP_MONGODB_URIcan supplydefaultwhen the JSON contains only secondary connections. Named connections default to a 5-second server selection timeout. SetserverSelectionTimeoutMSin the URI to override it.If a connection is offline,
resources/listreports its ID and fails. Tools targeting other connections remain usable.
Security
Database scope. The server operates on the selected database.
Named connections restrict selection to their configured databases.
Aggregation stages that reach another database ($out, $merge,
$lookup with an explicit db) are rejected by default, so a pipeline can't
quietly read from or write to databases you didn't point it at. Enable them
with --allow-cross-db if you need them. Named connections still enforce their
database allowlist.
Server-side JavaScript. The operators $function, $where, and
$accumulator are blocked by default in aggregation pipelines and in the
filters for query, count, and update. In read-write mode,
--allow-server-js enables these operators.
Read-only mode blocks writes, including the $out and $merge
aggregation stages. It also blocks server-side JavaScript even when
--allow-server-js is set.
Least privilege. Application-level checks only go so far — the strongest guarantee comes from the database. Connect with a MongoDB user scoped to just the database you need, with read-only permissions when the assistant only needs to explore. That way the database itself enforces the boundary, as defense in depth.
Documentation
Integration Guide — Claude Desktop, Windsurf, Cursor, Docker
Available Tools — query, aggregate, update, insert, and more
Development — setup, scripts, and debugging
License
MIT — see LICENSE for details.
Available Tools
8 toolsaggregateB
Execute a MongoDB aggregation pipeline with optional execution plan analysis
Inputs: pipeline (required), collection (required), explain, objectIdMode.
countC
Count documents in a collection matching a query
Inputs: collection (required), hint, skip, limit, +5 more.
createIndexB
Create one or more indexes on a MongoDB collection
Inputs: indexes (required), collection (required), commitQuorum, objectIdMode, +1 more.
insertB
Insert one or more documents into a MongoDB collection
Inputs: documents (required), collection (required), ordered, objectIdMode, +2 more.
listCollectionsB
List all collections in the MongoDB database
Inputs: filter, nameOnly, objectIdMode.
queryB
Execute a MongoDB query with optional execution plan analysis
Inputs: collection (required), limit, filter, explain, +2 more.
serverInfoA
Get MongoDB server information including version, storage engine, and other details
Inputs: includeDebugInfo.
updateC
Update documents in a MongoDB collection
Inputs: filter (required), update (required), collection (required), multi, +2 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool targets a distinct database operation: aggregation, counting, indexing, inserting, listing collections, querying, server info, and updating. No two tools have overlapping purposes.
All tool names use lowercase with camelCase for multi-word terms (e.g., 'createIndex', 'listCollections', 'serverInfo'), following a consistent pattern of verb or verb_noun.
8 tools cover core MongoDB operations (CRUD, aggregation, indexing, metadata) without being too few or excessive for a general-purpose database server.
The set lacks a tool for deleting documents or collections, which is a fundamental operation. Without 'delete' or 'remove', agents cannot complete typical data lifecycle actions, leaving a significant gap.
Maintenance
Related MCP Connectors
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
A Model Context Protocol server for Wix AI tools
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
The Mercado Pago MCP Server implements the Model Context Protocol to provide AI agents and LLMs with access to Mercado Pago's APIs and tools within compatible development environments. It acts as an intermediary that translates Mercado Pago resources into executable functions (tools) that AI applications can invoke to perform actions and automate flows. The server simplifies integration, enables using documentation to implement or improve code, and optimizes operations through natural language interactions without manual implementations.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that enables LLMs to interact directly with MongoDB databases. Query collections, inspect schemas, and manage data seamlessly through natural language.23 npm176MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.23 npm1MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.23 npmMIT
- AlicenseDqualityDmaintenanceA Model Context Protocol server that enables LLMs to interact with databases (currently MongoDB) through natural language, supporting operations like querying, inserting, deleting documents, and running aggregation pipelines.514 npmMIT