MongoDB MCP Server
Provides tools for querying MongoDB databases, including listing databases, collections, indexes, and running aggregation pipelines.
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 MCP Serverlist all collections in the sales database"
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.
MongoDB MCP Server
A read-only Model Context Protocol (MCP) server for querying MongoDB databases. Designed to be used with MCP-compatible clients like Claude Code, Claude Desktop, etc.
Quick Start
Run directly with npx — no installation needed:
MONGODB_URI="mongodb://localhost:27017" npx mongodb-mcpOr install globally:
npm install -g mongodb-mcpRelated MCP server: mongo-mcp
Environment Variables
Variable | Required | Description |
| Yes | MongoDB connection string (e.g. |
Configuration
Claude Code
Add to your .mcp.json:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["mongodb-mcp"],
"env": {
"MONGODB_URI": "mongodb+srv://user:pass@cluster.mongodb.net/dbname"
}
}
}
}Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["mongodb-mcp"],
"env": {
"MONGODB_URI": "mongodb+srv://user:pass@cluster.mongodb.net/dbname"
}
}
}
}Tools
list_databases
Lists all databases on the connected MongoDB instance.
list_collections
Lists all collections in a given database.
Parameter | Type | Description |
| string | The database name |
list_indexes
Lists all indexes on a collection.
Parameter | Type | Description |
| string | The database name |
| string | The collection name |
run_aggregation
Runs an aggregation pipeline on a collection.
Parameter | Type | Description |
| string | The database name |
| string | The collection name |
| object[] | The aggregation pipeline stages |
run_aggregation_to_file
Runs an aggregation pipeline and writes results to a JSON file on disk instead of returning them over MCP. Returns only metadata (document count, file path, file size), which avoids loading large result sets into the agent's context window. Use CLI tools like jq, head, or the Read tool to selectively inspect the output file.
Parameter | Type | Description |
| string | The database name |
| string | The collection name |
| object[] | The aggregation pipeline stages |
| string | Absolute file path where JSON results are written |
Safety
Read-only mode — Write stages (
$out,$merge) in aggregation pipelines are rejected with an error.Query timeout — Aggregation queries have a 50-second server-side timeout (
maxTimeMS) to prevent runaway queries.Read preference — The connection uses
secondaryPreferredread preference as defense in depth.
Development
npm run dev # watch mode
npm run build # compile TypeScript
npm start # run the compiled serverLicense
MIT
Available Tools
5 toolslist_collectionsA
List all collections in a given database
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | The database name |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must fully disclose behavior. It only states the basic operation without mentioning return format, whether system collections are included, or error behavior. This is minimal disclosure beyond what the name implies.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single concise sentence, front-loaded with the action and resource. Every word contributes to meaning, with no redundancy or filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple one-parameter tool, the description covers the core purpose but omits details about the response structure or edge cases. Given no output schema or annotations, a bit more context would be helpful, but the tool is low complexity.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema already describes the 'database' parameter with a clear definition. The description's phrase 'in a given database' adds no new semantic meaning beyond the schema, so baseline 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description 'List all collections in a given database' clearly specifies the action (list), the resource (collections), and the scope (database). It distinguishes from sibling tools like list_databases and list_indexes by naming the object type.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage for retrieving collections in a database but does not explicitly state when to choose this over alternatives or provide exclusions. It lacks guidance such as 'Use list_collections to enumerate collections, use list_indexes for index details.'
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_databasesA
List all databases on the connected MongoDB instance
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are present, so the description must indicate safety. The verb 'List' clearly implies a read-only operation, and 'connected MongoDB instance' provides useful context about the connection state. However, it doesn't explicitly confirm no side effects or state any permissions, but such omissions are minor for a listing operation.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, concise sentence that front-loads the verb and includes only essential information. There is no wasted wording or redundancy.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
With no output schema, the description should clarify what the tool returns. It only states the action ('List all databases') but does not specify the format or structure of the returned data (e.g., array of names vs. objects). For a simple read-only tool this is a minor gap, but it is still a gap.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool has zero parameters, so the baseline score is 4. The description doesn't need to add parameter info, and the empty schema is consistent. The phrase 'all databases' reinforces that there are no filters, which indirectly aligns with the lack of parameters.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('List') and the specific resource ('all databases') with a scope ('on the connected MongoDB instance'). This distinguishes it from siblings like list_collections and list_indexes, which operate on different levels.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage for enumerating databases but does not explicitly state when to prefer this tool over alternatives or provide any usage context. No exclusions or alternative tool names are mentioned, leaving the agent to infer based on the name.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_indexesB
List all indexes on a collection
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | The database name | |
| collection | Yes | The collection name |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It only states the basic action and lacks detail about return format, ordering, permissions, or error behavior. The read-only nature is implied but not explicit.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, well-structured sentence that immediately conveys the tool's purpose. There is no wasted wording or unnecessary detail.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's simplicity (two well-described parameters, no output schema), the description is minimally adequate. However, it could be more complete by clarifying what 'indexes' entails (e.g., names, keys, options) or potential side effects, though complexity is low.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema already provides descriptions for both parameters with 100% coverage. The description adds no additional semantic meaning beyond what the schema offers, so the baseline of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description 'List all indexes on a collection' clearly identifies the action (list), the specific resource (indexes), and the scope (a collection). It effectively distinguishes from sibling tools that list databases or collections.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. There is no mention of prerequisites, preferred contexts, or exclusions, leaving the agent to infer usage from the tool name alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
run_aggregationC
Run an aggregation pipeline on a collection
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | The database name | |
| pipeline | Yes | The aggregation pipeline stages | |
| collection | Yes | The collection name |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of disclosing behavioral traits. It only states the action and does not mention potential side effects (e.g., if the pipeline uses $out or $merge), return format, permissions, or any limitations. This is a significant transparency gap.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single sentence with no redundant words, making it concise and front-loaded. However, it is quite terse and lacks the detail that would make it fully helpful, but that is more a completeness issue rather than a conciseness issue.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a tool with three required parameters, no output schema, and no annotations, the description is incomplete. It does not explain the behavior of the pipeline, the return structure, or how it differs from the sibling run_aggregation_to_file. The description is too minimal to fully support an agent in selecting and invoking the tool correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, with each parameter (database, collection, pipeline) having a description in the schema. The tool description adds no additional parameter semantics, so the baseline of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description uses a specific verb 'Run' and identifies a clear resource: 'an aggregation pipeline on a collection'. It clearly states the core action, but it does not differentiate from the sibling tool run_aggregation_to_file, which also runs an aggregation pipeline (with a different output destination).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. Given the sibling run_aggregation_to_file, users are left without any information on which tool to choose based on their needs (e.g., in-memory results vs. file output).
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
run_aggregation_to_fileA
Run an aggregation pipeline on a collection and write results to a JSON file on disk. Returns only metadata (document count, file path, file size) instead of the actual documents, which avoids loading large result sets into the context window. Use CLI tools like jq, head, or the Read tool to selectively inspect the output file.
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | The database name | |
| pipeline | Yes | The aggregation pipeline stages | |
| collection | Yes | The collection name | |
| output_path | Yes | Absolute file path where JSON results will be written |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden. It discloses that only metadata is returned, the reason for this, and suggests how to handle the output file. A minor gap is not mentioning whether an existing file at output_path is overwritten or appended.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is three sentences, each earning its place: purpose, return metadata/benefit, and usage guidance. It is front-loaded and contains no filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no output schema and no annotations, the description covers the essential context: purpose, return value, and post-processing. It is slightly incomplete regarding file overwrite behavior, but otherwise adequate.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the baseline is 3. The description adds no extra parameter-level detail beyond what the schema already states; it does not clarify pipeline format or output_path handling.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action: running an aggregation pipeline and writing results to a JSON file. It distinguishes from the likely sibling tool run_aggregation by specifying that only metadata is returned, not the documents.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
It strongly implies when to use this tool (to avoid loading large result sets into context) and recommends CLI tools for inspecting the output. However, it does not explicitly name the alternative run_aggregation or state when not to use this tool.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
5 tool updates
v1.0.4- First observed
list_collections - First observed
list_databases - First observed
list_indexes - First observed
run_aggregation - First observed
run_aggregation_to_file
TDQS
Scored across 5 tools
Each tool targets a distinct operation: listing databases, collections, indexes, running aggregations, and running aggregations to file. The two aggregation tools are clearly differentiated by output method and purpose.
All tool names follow a consistent verb_noun pattern (list_* for enumeration, run_* for execution). No mixing of conventions or vague verbs.
Five tools is well-scoped for a focused MongoDB utility server. Each tool earns its place without redundancy or excessive breadth.
The set covers listing and aggregation but lacks common MongoDB operations such as find/query, insert, update, and delete. This leaves significant gaps for typical database usage, forcing agents to work around missing functionality.
Maintenance
Related MCP Connectors
An MCP server that provides read access to your cloud storage providers, bank accounts and more.
Read-only MCP server for The Quiet Protocol's engines, benchmarks, proof, and business data.
Read-only MCP server for ClassQuill, a tutoring-business-management platform.
Curated, trust-first index of vetted MCP servers — scored tiers, monthly re-verified. Read-only.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA lightweight MCP server for MongoDB 3.6+ providing read, write, metadata, and management tools.7 npm1MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that enables querying, inserting, updating, deleting, aggregating, and listing collections in MongoDB via natural language commands.19 npmMIT
- FlicenseNot gradedqualityCmaintenanceRead-only MCP server for MongoDB ERP analytics with catalog-driven collection allowlist and safe find/aggregate tools.1-
- AlicenseNot gradedqualityBmaintenanceA secure, read-only MCP server that enables AI agents to connect to MongoDB, perform queries and aggregations, and manage connections.186 npmMIT