Skip to main content
Glama
linzi007

mongodb36-mcp-server

by linzi007

MongoDB 3.6+ MCP Server

License: MIT Node.js Version MongoDB Version

A Model Context Protocol (MCP) server implementation for MongoDB 3.6 and above. This server enables AI assistants like Claude to interact with MongoDB databases through a standardized interface.

Features

  • āœ… MongoDB 3.6+ Compatible: Works with MongoDB 3.6 and all newer versions

  • šŸ”§ Standard MCP Protocol: Implements the Model Context Protocol specification

  • šŸ› ļø Essential Operations: List collections, find documents, count, and aggregations

  • šŸ”’ Environment-based Configuration: Secure configuration through environment variables

  • šŸ“¦ Zero Default Values: Requires explicit configuration for security

Related MCP server: MongoDB MCP Server

Installation

Prerequisites

  • Node.js >= 14.0.0

  • MongoDB 3.6 or higher

  • Access to a MongoDB instance

Install from npm

npm install -g mongodb36-mcp-server

Install from source

git clone https://github.com/linzi007/mongodb36-mcp-server.git
cd mongodb36-mcp-server
npm install
chmod +x index.js

Configuration

This server requires environment variables to be set. No default values are provided to ensure secure and explicit configuration.

Required Environment Variables

Variable

Description

Example

MONGODB_CONNECTION_STRING

MongoDB connection URI

mongodb://localhost:27017

MONGODB_DB_NAME

Database name to use

myDatabase

Setting Environment Variables

Linux/macOS:

export MONGODB_CONNECTION_STRING="mongodb://localhost:27017"
export MONGODB_DB_NAME="myDatabase"

Windows (Command Prompt):

set MONGODB_CONNECTION_STRING=mongodb://localhost:27017
set MONGODB_DB_NAME=myDatabase

Windows (PowerShell):

$env:MONGODB_CONNECTION_STRING="mongodb://localhost:27017"
$env:MONGODB_DB_NAME="myDatabase"

Usage

Claude Desktop Configuration

Add this server to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": ["-y", "mongodb36-mcp-server"],
      "env": {
        "MONGODB_CONNECTION_STRING": "mongodb://localhost:27017",
        "MONGODB_DB_NAME": "myDatabase"
      }
    }
  }
}

Option 2: Using local installation

{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": ["/absolute/path/to/mongodb36-mcp-server/index.js"],
      "env": {
        "MONGODB_CONNECTION_STRING": "mongodb://localhost:27017",
        "MONGODB_DB_NAME": "myDatabase"
      }
    }
  }
}

Option 3: Using GitHub repository directly

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": ["-y", "github:linzi007/mongodb36-mcp-server"],
      "env": {
        "MONGODB_CONNECTION_STRING": "mongodb://localhost:27017",
        "MONGODB_DB_NAME": "myDatabase"
      }
    }
  }
}

Running Directly

MONGODB_CONNECTION_STRING="mongodb://localhost:27017" \
MONGODB_DB_NAME="myDatabase" \
node index.js

Available Tools

The server provides the following MCP tools:

1. list_collections

List all collections in the database.

Example:

List all collections in the database

2. find

Find documents in a collection.

Parameters:

  • collection (required): Collection name

  • filter (optional): MongoDB query filter

  • limit (optional): Maximum number of documents (default: 10)

Example:

Find documents in the "users" collection where age > 25, limit 5

3. find_one

Find a single document in a collection.

Parameters:

  • collection (required): Collection name

  • filter (optional): MongoDB query filter

Example:

Find one document in the "users" collection where email is "user@example.com"

4. count

Count documents in a collection.

Parameters:

  • collection (required): Collection name

  • filter (optional): MongoDB query filter

Example:

Count documents in the "orders" collection where status is "completed"

5. aggregate

Run an aggregation pipeline.

Parameters:

  • collection (required): Collection name

  • pipeline (required): Array of aggregation stages

Example:

Run aggregation on "sales" collection to group by product and sum quantities

Security Considerations

Connection String Security

  • āš ļø Never commit credentials to version control

  • āœ… Use environment variables for sensitive data

  • āœ… Consider using MongoDB connection string with authentication: mongodb://username:password@host:port

  • āœ… Use SSL/TLS for production: mongodb://host:port?ssl=true

Network Security

  • šŸ”’ Ensure MongoDB instance is not exposed to the public internet

  • šŸ”’ Use firewall rules to restrict access

  • šŸ”’ Enable MongoDB authentication and authorization

  • šŸ”’ Use VPN or SSH tunneling for remote connections

Best Practices

  1. Use read-only credentials when possible

  2. Limit database access to only required collections

  3. Monitor query performance to prevent resource exhaustion

  4. Set connection limits in MongoDB

  5. Use separate databases for development and production

Development

Project Structure

mongodb36-mcp-server/
ā”œā”€ā”€ index.js          # Main server implementation
ā”œā”€ā”€ package.json      # Package configuration
ā”œā”€ā”€ README.md         # This file
ā”œā”€ā”€ LICENSE           # MIT License
└── .gitignore        # Git ignore rules

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository

  2. Create a feature branch (git checkout -b feature/amazing-feature)

  3. Commit your changes (git commit -m 'Add amazing feature')

  4. Push to the branch (git push origin feature/amazing-feature)

  5. Open a Pull Request

Troubleshooting

Error: MONGODB_CONNECTION_STRING environment variable is required

Solution: Set the MONGODB_CONNECTION_STRING environment variable before running the server.

Error: Failed to connect to MongoDB

Possible causes:

  • MongoDB is not running

  • Incorrect connection string

  • Network firewall blocking connection

  • Authentication failure

Solution:

  • Verify MongoDB is running: mongo --version

  • Test connection: mongo "your-connection-string"

  • Check firewall settings

  • Verify credentials

Error: Database not found

Solution: Ensure the database name in MONGODB_DB_NAME exists or will be created on first write.

Examples

Basic Query Example

// In Claude Desktop, you can ask:
"Show me all users in the users collection"

// This will call the find tool:
{
  "collection": "users",
  "filter": {},
  "limit": 10
}

Aggregation Example

// In Claude Desktop, you can ask:
"Calculate the average order value by customer from the orders collection"

// This will call the aggregate tool:
{
  "collection": "orders",
  "pipeline": [
    {
      "$group": {
        "_id": "$customer_id",
        "avgOrderValue": { "$avg": "$total" }
      }
    }
  ]
}

Compatibility

MongoDB Versions

  • āœ… MongoDB 3.6.x

  • āœ… MongoDB 4.0.x

  • āœ… MongoDB 4.2.x

  • āœ… MongoDB 4.4.x

  • āœ… MongoDB 5.0.x

  • āœ… MongoDB 6.0.x

  • āœ… MongoDB 7.0.x

Node.js Versions

  • āœ… Node.js 14.x

  • āœ… Node.js 16.x

  • āœ… Node.js 18.x

  • āœ… Node.js 20.x

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Support


Made with ā¤ļø for the AI and MongoDB communities

Available Tools

5 tools
aggregateC

Run an aggregation pipeline

ParametersJSON Schema
NameRequiredDescriptionDefault
pipelineYesAggregation pipeline stages
collectionYesCollection name

TDQS

C2.8/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description bears the full burden of behavioral disclosure. It only states the operation type without revealing whether results are returned as a stream, a single document, or aggregated values, and it omits side effects, authorization needs, or performance considerations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is short and direct, but it is under-specified rather than efficiently informative. It conveys the core action in one clause but provides no additional structured detail that would help an agent use the tool correctly.

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?

With no output schema and no annotations, the description should explain return behavior, pipeline expectations, and usage context. It does none of that, so the agent is left without enough information to confidently predict the outcome of invoking this tool.

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 fully documents both parameters with descriptions, so the schema carries the semantic weight. The description adds no parameter-level meaning, which is acceptable given the 100% schema coverage.

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 names a specific operation, running an aggregation pipeline, which is distinct from sibling tools like find, count, and list_collections. It is clear about the action and resource, though it does not explicitly contrast itself with siblings.

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?

No guidance is given about when to use aggregate versus find, count, or list_collections. The description does not mention use cases, limitations, or alternatives, leaving the agent to infer the appropriate context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

countA

Count documents in a collection

ParametersJSON Schema
NameRequiredDescriptionDefault
filterNoQuery filter (MongoDB query syntax)
collectionYesCollection name

TDQS

A3.6/5.0
Behavior3/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 behavioral disclosure. It states the core operation (counting documents) and implies a read-only action, but it does not mention how the optional filter affects the count, whether the count is exact or estimated, or what the response format is. This is a moderate but not severe gap for a simple read 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, front-loaded sentence containing only the essential information. Every word earns its place and there is no filler, making it highly scannable.

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?

For a two-parameter tool, the description plus schema is mostly sufficient to select and invoke it. The sibling context and the simple operation cover most needs. However, with no output schema or annotations, it would be slightly stronger to explicitly state that it returns a count and that omitting the filter counts all documents in the collection.

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 itself adds no parameter meaning beyond what the schema already provides: 'collection' and 'filter' are both documented, with the filter explicitly described as MongoDB query syntax. The description's 'in a collection' mirrors the existing collection parameter without adding insight.

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 uses a specific verb ('Count'), a resource ('documents in a collection'), and clearly identifies the operation. It is distinct from siblings like find (returns documents) and aggregate (pipeline processing), so an agent can tell it apart without opening the schema.

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?

There is no guidance about when to use count versus aggregate or find, nor any mention of exclusions or alternative tools. Sibling tools overlap in capability (aggregate can also count), and the description does not help an agent choose between them.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

findC

Find documents in a collection

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of documents to return
filterNoQuery filter (MongoDB query syntax)
collectionYesCollection name

TDQS

C2.8/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, but it only restates the basic purpose. It does not explain that the filter is optional, that limit defaults to 10, what the return shape looks like, or whether the operation is read-only. The description is not misleading, but it provides almost no behavioral detail beyond the name.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is one short, front-loaded sentence with no filler, which is structurally clean. However, it is under-specified for a tool with three parameters and no annotations; conciseness edges into incompleteness. The sentence earns its place but does not carry enough useful information to be highly rated.

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?

The tool is relatively simple, but with no output schema and no annotations, the description must cover return behavior and selection context. It only states the basic purpose, leaving default-limit behavior, optional filter semantics, and differences from find_one or aggregate unaddressed. This is insufficient for confident tool selection and invocation.

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 even with no parameter details in the description. The description only mentions the collection as the target and does not add meaning to filter or limit beyond what the schema already documents. This meets the baseline but does not exceed it.

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 states a specific action ('Find') and a resource ('documents in a collection'), so an agent can tell it returns documents. However, it does not explicitly differentiate from the sibling find_one, and only the plural 'documents' hints that it returns multiple records. It is clear but lacks overt sibling distinction.

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 offers no guidance on when to use this tool versus find_one, count, or aggregate. Sibling tools are listed but never referenced, and no conditions, exclusions, or preferred alternatives are mentioned. An agent must infer usage entirely from the tool name and schema.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

find_oneB

Find a single document in a collection

ParametersJSON Schema
NameRequiredDescriptionDefault
filterNoQuery filter (MongoDB query syntax)
collectionYesCollection name

TDQS

B3.2/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, and it does not disclose key edge-case behavior: what happens when no document matches (null vs error), which document is returned when multiple match (e.g., natural order), or whether invalid Mongo query syntax errors out. These are important traits for an agent invoking this tool on unknown data.

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?

A single, front-loaded sentence with zero filler words; the verb comes first and the resource is immediately clear. It is concise without being bloated, though a short second sentence on return behavior would have improved it without harming brevity.

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 two-parameter tool with 100% schema coverage, the description is minimally adequate. However, with no output schema and no annotations, the description should have disclosed the return value shape (document vs null) and multi-match behavior to be complete; these gaps are the main deficit.

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% — 'filter' documents MongoDB query syntax and 'collection' is described as the collection name — so the schema already carries the parameter meaning. The description adds no parameter-level detail beyond this, so the baseline 3 applies.

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 states a specific verb ('Find') and resource ('a single document in a collection'). The qualifier 'single' usefully differentiates it from the sibling 'find', which presumably returns multiple documents, and 'count'/'aggregate'. However, it does not name the sibling explicitly and is close to a light restatement of the tool name.

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?

Usage context is only implied through the word 'single', suggesting the tool is for retrieving exactly one matching document. There is no explicit when-to-use guidance, no mention of alternatives like 'find' for multiple results or 'count' for counting matches, and no exclusion criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_collectionsA

List all collections in the database

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

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 of behavioral disclosure. It clearly conveys a read-only enumeration behavior with no visible side effects. It does not mention edge cases like system collections or exact return shape, but for such a simple operation the core behavior is transparent.

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, clear sentence with no filler or redundant wording. Every word contributes meaning, and the key information is front-loaded.

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?

For a zero-parameter read-only listing tool, the description is largely complete: it states the action, the resource, and the scope. The only minor gap is that it does not specify the return format, though 'list all collections' conventionally implies a list of collection names.

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 there is nothing for the description to add beyond what the empty schema conveys. This matches the baseline of 4 for parameter-less tools.

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 uses a specific verb ('List') and resource ('collections') with a clear scope ('all in the database'). It also differentiates from sibling tools like find, count, and aggregate, which operate on documents inside collections rather than enumerating collections themselves.

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 the tool is for database-level enumeration rather than document-level operations, but it does not explicitly state when to use it over the sibling tools. There is no mention of alternatives or conditions that would select a different 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.0
    • First observedaggregate
    • First observedcount
    • First observedfind
    • First observedfind_one
    • First observedlist_collections

TDQS

B3.3/5.0

Scored across 5 tools

Disambiguation4/5

Find and find_one are similar but clearly separated by singular vs plural result intent. Count, aggregate, and list_collections each have distinct purposes, so an agent can reliably choose the right tool.

Naming Consistency4/5

All tool names use lowercase snake_case and follow familiar MongoDB terminology. list_collections follows verb_noun while find, find_one, count, and aggregate are verb-only, but the naming is still predictable and readable.

Tool Count5/5

Five tools is well-scoped for a read-only MongoDB query server. Each tool covers a distinct core operation without redundancy or bloat.

Completeness2/5

The tool set only supports reading and querying data; there are no create, update, or delete operations. As a general MongoDB server this is a significant gap, leaving agents unable to perform basic write workflows.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables LLMs to interact with MongoDB databases through a complete suite of CRUD operations, administrative tasks, and index management tools. It supports database and collection handling, aggregation pipelines, and comprehensive server monitoring via the Model Context Protocol.
    775 PyPI
    3
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to interact natively with MongoDB databases, including schema discovery, CRUD operations, aggregation pipelines, and index management via natural language.
    28 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to interact with MongoDB databases through natural language, supporting document CRUD, aggregation, collection listing, and statistics.
    82,973 npm
    Apache 2.0
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to interact with MongoDB databases and MongoDB Atlas, supporting read-only and write operations, Atlas cluster management, and data exploration.
    82,973 npm
    Apache 2.0