Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

mongodb-mcp-server

MCP.Pizza Chef: mongodb-developer

The mongodb-mcp-server is a community-maintained Model Context Protocol server that offers read-only access to MongoDB databases. It enables large language models (LLMs) to inspect collection schemas and execute complex aggregation pipelines, facilitating advanced data querying and analysis within the MCP ecosystem. This server supports executing MongoDB aggregation pipelines with customizable options such as disk usage allowance, execution time limits, and operation comments. It is designed to integrate MongoDB data sources into AI workflows securely and efficiently, enhancing real-time model interactions with database content.

Use This MCP server To

Inspect MongoDB collection schemas for data understanding Execute aggregation pipelines for complex data queries Integrate MongoDB data into AI-driven workflows Enable LLMs to analyze MongoDB data in real time Perform read-only database operations securely

README

šŸ“¢ COMMUNITY SERVER NOTICE
This is a community-maintained MCP Server.
šŸ‘‰ For the official MongoDB MCP Server, visit mongodb-js/mongodb-mcp-server

MongoDB MCP Server

A Model Context Protocol server that provides read-only access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute aggregation pipelines.

Components

Tools

  • aggregate

    • Execute MongoDB aggregation pipelines against the connected database
    • Input:
      • collection (string): The collection to query
      • pipeline (array): MongoDB aggregation pipeline stages
      • options (object): Optional aggregation settings
        • allowDiskUse (boolean): Allow operations that require disk usage
        • maxTimeMS (number): Maximum execution time in milliseconds
        • comment (string): Comment to identify the operation
    • Default limit of 1000 documents if no limit stage is specified
    • Default timeout of 30 seconds
  • explain

    • Get execution plans for aggregation pipelines
    • Input:
      • collection (string): The collection to analyze
      • pipeline (array): MongoDB aggregation pipeline stages
      • verbosity (string): Detail level of the explanation
        • Options: "queryPlanner", "executionStats", "allPlansExecution"
        • Default: "queryPlanner"

Resources

The server provides schema information for each collection in the database:

  • Collection Schemas (mongodb://<host>/<collection>/schema)
    • Inferred JSON schema information for each collection
    • Includes field names and data types
    • Schema is derived from sampling collection documents

Usage with Claude Desktop

To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json:

"mongodb": {
      "command": "npx",
      "args": [
        "-y" ,
        "@pash1986/mcp-server-mongodb"
      ],
     "env" : {
	"MONGODB_URI" : "mongodb+srv://<yourcluster>" // 'mongodb://localhost:27017'
	}
    }

Replace mydb with your database name and adjust the connection string as needed.

Example Usage

Basic Aggregation

{
  "collection": "users",
  "pipeline": [
    { "$match": { "age": { "$gt": 21 } } },
    { "$group": {
      "_id": "$city",
      "avgAge": { "$avg": "$age" },
      "count": { "$sum": 1 }
    }},
    { "$sort": { "count": -1 } },
    { "$limit": 10 }
  ],
  "options": {
    "allowDiskUse": true,
    "maxTimeMS": 60000,
    "comment": "City-wise user statistics"
  }
}

Query Explanation

{
  "collection": "users",
  "pipeline": [
    { "$match": { "age": { "$gt": 21 } } },
    { "$sort": { "age": 1 } }
  ],
  "verbosity": "executionStats"
}

Safety Features

  • Automatic limit of 1000 documents if no limit is specified in the pipeline
  • Default timeout of 30 seconds for all operations
  • Read-only operations only
  • Safe schema inference from collection samples

License

This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

mongodb-mcp-server FAQ

How do I connect the mongodb-mcp-server to my MongoDB instance?
You configure the server with your MongoDB connection URI and credentials, ensuring read-only access for security.
Can the mongodb-mcp-server modify data in the database?
No, it provides read-only access to ensure data integrity and security.
What aggregation options does the server support?
It supports options like allowDiskUse, maxTimeMS for execution time limits, and comments to identify operations.
Is this the official MongoDB MCP server?
No, this is a community-maintained server. The official server is available at mongodb-js/mongodb-mcp-server on GitHub.
How does the server handle large aggregation queries?
It supports allowDiskUse to enable disk usage for large operations and maxTimeMS to limit execution time.
Can I use this server with different LLM providers?
Yes, it is designed to work with various LLMs like OpenAI, Claude, and Gemini through the MCP protocol.
What security measures are recommended when using this server?
Use read-only credentials, restrict network access, and monitor query usage to maintain security.