mongo-mcp

MCP.Pizza Chef: QuantGeekDev

mongo-mcp is a Model Context Protocol (MCP) server that allows large language models (LLMs) to interact directly with MongoDB databases. It supports querying collections, inspecting collection schemas, managing indexes, and performing document operations such as insert, update, and delete. Designed for seamless integration, mongo-mcp enables natural language-driven database management and data retrieval, enhancing AI workflows with real-time access to MongoDB data. It supports secure and efficient interaction with MongoDB, making it ideal for developers building AI-powered applications that require dynamic database context.

Use This MCP server To

Query MongoDB collections using natural language Inspect MongoDB collection schemas dynamically Manage MongoDB indexes programmatically Insert, update, and delete MongoDB documents via LLMs Enable AI agents to access real-time MongoDB data Integrate MongoDB data into AI-enhanced workflows

README

πŸ—„οΈ MongoDB MCP Server for LLMS

Node.js 18+ License: MIT smithery badge

A 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.

✨ Features

  • πŸ” Collection schema inspection
  • πŸ“Š Document querying and filtering
  • πŸ“ˆ Index management
  • πŸ“ Document operations (insert, update, delete)

Demo Video

mongo-mcp-demo-gh.mp4

πŸš€ Quick Start

To get started, find your mongodb connection url and add this configuration to your Claude Desktop config file:

MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "mongo-mcp",
        "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
      ]
    }
  }
}

Installing via Smithery

To install MongoDB MCP Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install mongo-mcp --client claude

Prerequisites

  • Node.js 18+
  • npx
  • Docker and Docker Compose (for local sandbox testing only)
  • MCP Client (Claude Desktop App for example)

Test Sandbox Setup

If you don't have a mongo db server to connect to and want to create a sample sandbox, follow these steps

  1. Start MongoDB using Docker Compose:
docker-compose up -d
  1. Seed the database with test data:
npm run seed

Configure Claude Desktop

Add this configuration to your Claude Desktop config file:

MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

Local Development Mode:

{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": [
        "dist/index.js",
        "mongodb://root:example@localhost:27017/test?authSource=admin"
      ]
    }
  }
}

Test Sandbox Data Structure

The seed script creates three collections with sample data:

Users

  • Personal info (name, email, age)
  • Nested address with coordinates
  • Arrays of interests
  • Membership dates

Products

  • Product details (name, SKU, category)
  • Nested specifications
  • Price and inventory info
  • Tags and ratings

Orders

  • Order details with items
  • User references
  • Shipping and payment info
  • Status tracking

🎯 Example Prompts

Try these prompts with Claude to explore the functionality:

Basic Operations

"What collections are available in the database?"
"Show me the schema for the users collection"
"Find all users in San Francisco"

Advanced Queries

"Find all electronics products that are in stock and cost less than $1000"
"Show me all orders from the user john@example.com"
"List the products with ratings above 4.5"

Index Management

"What indexes exist on the users collection?"
"Create an index on the products collection for the 'category' field"
"List all indexes across all collections"

Document Operations

"Insert a new product with name 'Gaming Laptop' in the products collection"
"Update the status of order with ID X to 'shipped'"
"Find and delete all products that are out of stock"

πŸ“ Available Tools

The server provides these tools for database interaction:

Query Tools

  • find: Query documents with filtering and projection
  • listCollections: List available collections
  • insertOne: Insert a single document
  • updateOne: Update a single document
  • deleteOne: Delete a single document

Index Tools

  • createIndex: Create a new index
  • dropIndex: Remove an index
  • indexes: List indexes for a collection

πŸ“œ License

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

mongo-mcp FAQ

How do I configure mongo-mcp with my MongoDB instance?
Add your MongoDB connection URL to the Claude Desktop config file or your MCP host configuration to enable mongo-mcp to connect securely.
Can mongo-mcp handle complex MongoDB queries?
Yes, mongo-mcp supports querying and filtering documents, allowing LLMs to perform complex data retrieval operations.
Does mongo-mcp support schema inspection?
Yes, it provides collection schema inspection so models can understand the structure of your MongoDB data.
What document operations can mongo-mcp perform?
It supports inserting, updating, and deleting documents within MongoDB collections.
Is mongo-mcp compatible with multiple LLM providers?
Yes, mongo-mcp works with various LLMs including OpenAI, Anthropic Claude, and Google Gemini by exposing MongoDB data through MCP.
How does mongo-mcp ensure secure database access?
It relies on secure connection strings and scoped permissions configured in your MongoDB instance and MCP host environment.
Can I manage MongoDB indexes using mongo-mcp?
Yes, mongo-mcp includes features for index management to optimize query performance.
What Node.js version is required to run mongo-mcp?
mongo-mcp requires Node.js version 18 or higher.