Skip to main content
Glama
Sanjeev4523

MongoDB MCP Server

by Sanjeev4523

MongoDB MCP Server

npm version License: MIT

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-mcp

Or install globally:

npm install -g mongodb-mcp

Related MCP server: mongo-mcp

Environment Variables

Variable

Required

Description

MONGODB_URI

Yes

MongoDB connection string (e.g. mongodb://localhost:27017 or mongodb+srv://...)

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

database

string

The database name

list_indexes

Lists all indexes on a collection.

Parameter

Type

Description

database

string

The database name

collection

string

The collection name

run_aggregation

Runs an aggregation pipeline on a collection.

Parameter

Type

Description

database

string

The database name

collection

string

The collection name

pipeline

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

database

string

The database name

collection

string

The collection name

pipeline

object[]

The aggregation pipeline stages

output_path

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 secondaryPreferred read preference as defense in depth.

Development

npm run dev    # watch mode
npm run build  # compile TypeScript
npm start      # run the compiled server

License

MIT

Available Tools

5 tools
list_collectionsA

List all collections in a given database

ParametersJSON Schema
NameRequiredDescriptionDefault
databaseYesThe database name

TDQS

A3.5/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters3/5

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.

Purpose5/5

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.

Usage Guidelines3/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.1/5.0
Behavior4/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters4/5

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.

Purpose5/5

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.

Usage Guidelines3/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
databaseYesThe database name
collectionYesThe collection name

TDQS

B3.3/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters3/5

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.

Purpose5/5

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.

Usage Guidelines2/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
databaseYesThe database name
pipelineYesThe aggregation pipeline stages
collectionYesThe collection name

TDQS

C2.9/5.0
Behavior2/5

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.

Conciseness4/5

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.

Completeness2/5

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.

Parameters3/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
databaseYesThe database name
pipelineYesThe aggregation pipeline stages
collectionYesThe collection name
output_pathYesAbsolute file path where JSON results will be written

TDQS

A4.2/5.0
Behavior4/5

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.

Conciseness5/5

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.

Completeness4/5

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.

Parameters3/5

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.

Purpose5/5

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.

Usage Guidelines4/5

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.

  1. 5 tool updatesv1.0.4
    • First observedlist_collections
    • First observedlist_databases
    • First observedlist_indexes
    • First observedrun_aggregation
    • First observedrun_aggregation_to_file

TDQS

A3.6/5.0

Scored across 5 tools

Disambiguation5/5

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.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (list_* for enumeration, run_* for execution). No mixing of conventions or vague verbs.

Tool Count5/5

Five tools is well-scoped for a focused MongoDB utility server. Each tool earns its place without redundancy or excessive breadth.

Completeness2/5

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

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that enables querying, inserting, updating, deleting, aggregating, and listing collections in MongoDB via natural language commands.
    19 npm
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    A secure, read-only MCP server that enables AI agents to connect to MongoDB, perform queries and aggregations, and manage connections.
    186 npm
    MIT