Back to MCP Catalog

MongoDB Database Manager MCP Server

DatabasesTypeScript
Interact with MongoDB databases through natural language
Available Tools

listCollections

List all collections in the MongoDB database

find

Query documents with filtering and projection

insertOne

Insert a single document into a collection

updateOne

Update a single document in a collection

deleteOne

Delete a single document from a collection

createIndex

Create a new index on a collection

dropIndex

Remove an index from a collection

indexes

List all indexes for a collection

MongoDB Database Manager provides a seamless interface for LLMs to interact directly with MongoDB databases. It enables AI assistants to query collections, inspect schemas, and manage data through natural language commands without requiring users to write complex MongoDB queries. With this tool, you can perform a wide range of database operations including document querying, filtering, index management, and CRUD operations (Create, Read, Update, Delete). The server acts as a bridge between natural language instructions and MongoDB's query language, making database interactions more accessible.

Overview

MongoDB Database Manager allows AI assistants to interact with MongoDB databases through natural language. This tool bridges the gap between conversational requests and MongoDB's query language, enabling seamless database operations without writing complex queries.

Installation

Prerequisites

  • Node.js 18 or higher
  • A MongoDB database (local or remote)
  • Claude Desktop or another compatible MCP client

Setup Instructions

  1. Install the package

    You can install the MongoDB Database Manager using npm:

    npm install -g mongo-mcp
    

    Alternatively, you can use npx to run it without installation.

  2. Configure your MCP client

    Add the MongoDB Database Manager to your Claude Desktop configuration file:

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

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

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

    If you prefer an automated setup, you can use Smithery:

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

Testing with a Sandbox Environment

If you don't have a MongoDB server available, you can set up a test environment:

  1. Start a MongoDB container with Docker:

    Create a docker-compose.yml file with:

    version: '3.1'
    services:
      mongo:
        image: mongo
        restart: always
        ports:
          - 27017:27017
        environment:
          MONGO_INITDB_ROOT_USERNAME: root
          MONGO_INITDB_ROOT_PASSWORD: example
    

    Then run:

    docker-compose up -d
    
  2. Configure for local development:

    Update your Claude Desktop config to point to the local MongoDB instance:

    {
      "mcpServers": {
        "mongodb": {
          "command": "npx",
          "args": [
            "mongo-mcp",
            "mongodb://root:example@localhost:27017/test?authSource=admin"
          ]
        }
      }
    }
    

Usage

Once configured, you can interact with your MongoDB database through natural language. Here are some example prompts to try:

Basic Database Exploration

  • "What collections are available in the database?"
  • "Show me the schema for the users collection"
  • "How many documents are in the products collection?"

Querying Data

  • "Find all users in San Francisco"
  • "Show me products that cost less than $50"
  • "List orders placed in the last 7 days"

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"

Troubleshooting

If you encounter issues:

  1. Connection Problems:

    • Verify your MongoDB connection string is correct
    • Ensure your MongoDB server is running and accessible
    • Check network permissions and firewall settings
  2. Permission Issues:

    • Confirm the user in your connection string has appropriate permissions
    • For local development, try using the MongoDB root user
  3. Client Configuration:

    • Restart your Claude Desktop app after changing the configuration
    • Verify the config file format is valid JSON

Related MCPs

Milvus Vector Database
DatabasesPython

Connect to Milvus vector database for semantic search and vector operations

MotherDuck DuckDB
DatabasesPython

SQL analytics with DuckDB and MotherDuck for AI assistants

Alibaba Cloud Tablestore
DatabasesJava, Python

Connect to Alibaba Cloud Tablestore for vector search and RAG applications

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.