mo

mongo-mcp

MongoDB integration that enables LLMs to interact directly with databases.

Publishermongo-mcp
Submitted date4/13/2025

๐Ÿง  Unleash LLMs on Your MongoDB: Introducing the MongoDB MCP Server

Connect your Large Language Models (LLMs) directly to your MongoDB database with the power of the Model Context Protocol (MCP). This server empowers LLMs to understand, query, and manipulate your data using natural language, opening up a new world of AI-driven applications.

โœจ Key Capabilities

  • Schema Discovery: Introspect your MongoDB collections and understand their structure.
  • Intelligent Querying: Retrieve data with complex filters and projections using natural language.
  • Data Manipulation: Insert, update, and delete documents seamlessly.
  • Index Management: Optimize query performance by creating and managing indexes.

๐Ÿš€ Get Started in Minutes

Prerequisites

  • Node.js: Version 18 or higher.
  • npm/npx: Node Package Manager (usually included with Node.js).
  • MCP Client: An application that supports the Model Context Protocol (e.g., Claude Desktop).
  • MongoDB Instance: A running MongoDB server.

Installation

  1. Configure your MCP Client (e.g., Claude Desktop):

    Locate the configuration file:

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

    Add the following configuration, replacing the connection string with your MongoDB credentials:

    { "mcpServers": { "mongodb": { "command": "npx", "args": [ "mongo-mcp", "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin" ] } } }
  2. (Optional) Quick Sandbox Setup:

    If you don't have a MongoDB instance, use Docker Compose to create a local sandbox:

    docker-compose up -d npm run seed

    This will start a MongoDB instance and populate it with sample data.

Local Development Mode (Alternative Configuration)

For local development, you can run the server directly:

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

๐Ÿงช Explore Example Prompts

Unleash the power of natural language with these example prompts:

Basic Data Access

"List all available collections in the database." "Describe the schema of the 'users' collection." "Find all users located in San Francisco."

Advanced Data Retrieval

"Find all 'electronics' products in stock with a price under $1000." "Show me all orders placed by the user with the email '[email protected]'." "List products with an average rating above 4.5 stars."

Index Management Examples

"What indexes are currently defined on the 'users' collection?" "Create an index on the 'products' collection for the 'category' field to improve search performance." "Show me a comprehensive list of all indexes across all collections in the database."

Data Modification Examples

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

๐Ÿ› ๏ธ Available Tools for LLM Interaction

The MongoDB MCP Server exposes the following tools to your LLMs:

Data Querying Tools

  • find: Retrieve documents based on specified criteria (filtering and projection supported).
  • listCollections: Discover available collections within the database.
  • insertOne: Add a single document to a collection.
  • updateOne: Modify a single document within a collection.
  • deleteOne: Remove a single document from a collection.

Index Management Tools

  • createIndex: Create a new index on a collection to optimize query performance.
  • dropIndex: Remove an existing index from a collection.
  • indexes: List all indexes defined for a specific collection.

๐Ÿ“š Understanding the Test Sandbox Data

The optional sandbox setup populates your MongoDB instance with three collections:

  • Users: Contains personal information (name, email, age), nested addresses with coordinates, arrays of interests, and membership dates.
  • Products: Includes product details (name, SKU, category), nested specifications, price and inventory information, tags, and ratings.
  • Orders: Contains order details with items, user references, shipping and payment information, and status tracking.

This sample data provides a realistic environment for testing and exploring the capabilities of the MongoDB MCP Server.

Visit More

View All