Cover image
Try Now
2025-04-13

A Model Context Protocol Server for MongoDB

3 years

Works with Finder

2

Github Watches

15

Github Forks

134

Github Stars

MCP MongoDB Server


NPM Version NPM Downloads NPM License smithery badge

A Model Context Protocol server that enables LLMs to interact with MongoDB databases. This server provides capabilities for inspecting collection schemas and executing MongoDB operations through a standardized interface.

Demo

MCP MongoDB Server Demo | Claude Desktop

Key Features

Smart ObjectId Handling

  • Intelligent conversion between string IDs and MongoDB ObjectId
  • Configurable with objectIdMode parameter:
    • "auto": Convert based on field names (default)
    • "none": No conversion
    • "force": Force all string ID fields to ObjectId

Flexible Configuration

  • Environment Variables:
    • MCP_MONGODB_URI: MongoDB connection URI
    • MCP_MONGODB_READONLY: Enable read-only mode when set to "true"
  • Command-line Options:
    • --read-only or -r: Connect in read-only mode

Read-Only Mode

  • Protection against write operations (update, insert, createIndex)
  • Uses MongoDB's secondary read preference for optimal performance
  • Ideal for safely connecting to production databases

MongoDB Operations

  • Read Operations:
    • Query documents with optional execution plan analysis
    • Execute aggregation pipelines
    • Count documents matching criteria
    • Get collection schema information
  • Write Operations (when not in read-only mode):
    • Update documents
    • Insert new documents
    • Create indexes

LLM Integration

  • Collection completions for enhanced LLM interaction
  • Schema inference for improved context understanding
  • Collection analysis for data insights

Installation

Global Installation

npm install -g mcp-mongo-server

For Development

# Clone repository
git clone https://github.com/kiliczsh/mcp-mongo-server.git
cd mcp-mongo-server

# Install dependencies
npm install

# Build
npm run build

# Development with auto-rebuild
npm run watch

Usage

Basic Usage

# Start server with MongoDB URI
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database

# Connect in read-only mode
npx -y mcp-mongo-server mongodb://muhammed:kilic@localhost:27017/database --read-only

Environment Variables

You can configure the server using environment variables, which is particularly useful for CI/CD pipelines, Docker containers, or when you don't want to expose connection details in command arguments:

# Set MongoDB connection URI
export MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database"

# Enable read-only mode
export MCP_MONGODB_READONLY="true"

# Run server (will use environment variables if no URI is provided)
npx -y mcp-mongo-server

Using environment variables in Claude Desktop configuration:

{
  "mcpServers": {
    "mongodb-env": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server"
      ],
      "env": {
        "MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database",
        "MCP_MONGODB_READONLY": "true"
      }
    }
  }
}

Using environment variables with Docker:

docker run -e MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database" \
           -e MCP_MONGODB_READONLY="true" \
           mcp-mongo-server

Integration with Claude Desktop

Manual Configuration

Add the server configuration to Claude Desktop's config file:

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

Command-line Arguments Approach:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://muhammed:kilic@localhost:27017/database"
      ]
    },
    "mongodb-readonly": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://muhammed:kilic@localhost:27017/database",
        "--read-only"
      ]
    }
  }
}

Environment Variables Approach:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server"
      ],
      "env": {
        "MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database"
      }
    },
    "mongodb-readonly": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server"
      ],
      "env": {
        "MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database",
        "MCP_MONGODB_READONLY": "true"
      }
    }
  }
}

GitHub Package Usage:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "github:kiliczsh/mcp-mongo-server",
        "mongodb://muhammed:kilic@localhost:27017/database"
      ]
    },
    "mongodb-readonly": {
      "command": "npx",
      "args": [
        "-y",
        "github:kiliczsh/mcp-mongo-server",
        "mongodb://muhammed:kilic@localhost:27017/database",
        "--read-only"
      ]
    }
  }
}

Integration with Windsurf and Cursor

The MCP MongoDB Server can be used with Windsurf and Cursor in a similar way to Claude Desktop.

Windsurf Configuration

Add the server to your Windsurf configuration:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://muhammed:kilic@localhost:27017/database"
      ]
    }
  }
}

Cursor Configuration

For Cursor, add the server configuration to your settings:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://muhammed:kilic@localhost:27017/database"
      ]
    }
  }
}

You can also use the environment variables approach with both Windsurf and Cursor, following the same pattern shown in the Claude Desktop configuration.

Automated Installation

Using Smithery:

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

Using mcp-get:

npx @michaellatman/mcp-get@latest install mcp-mongo-server

Available Tools

Query Operations

  • query: Execute MongoDB queries

    {
      collection: "users",
      filter: { age: { $gt: 30 } },
      projection: { name: 1, email: 1 },
      limit: 20,
      explain: "executionStats"  // Optional
    }
    
  • aggregate: Run aggregation pipelines

    {
      collection: "orders",
      pipeline: [
        { $match: { status: "completed" } },
        { $group: { _id: "$customerId", total: { $sum: "$amount" } } }
      ],
      explain: "queryPlanner"  // Optional
    }
    
  • count: Count matching documents

    {
      collection: "products",
      query: { category: "electronics" }
    }
    

Write Operations

  • update: Modify documents

    {
      collection: "posts",
      filter: { _id: "60d21b4667d0d8992e610c85" },
      update: { $set: { title: "Updated Title" } },
      upsert: false,
      multi: false
    }
    
  • insert: Add new documents

    {
      collection: "comments",
      documents: [
        { author: "user123", text: "Great post!" },
        { author: "user456", text: "Thanks for sharing" }
      ]
    }
    
  • createIndex: Create collection indexes

    {
      collection: "users",
      indexes: [
        {
          key: { email: 1 },
          unique: true,
          name: "email_unique_idx"
        }
      ]
    }
    

System Operations

  • serverInfo: Get MongoDB server details
    {
      includeDebugInfo: true  // Optional
    }
    

Debugging

Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:

npm run inspector

This will provide a URL to access the debugging tools in your browser.

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.

相关推荐

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • https://reddgr.com
  • Delivers concise Python code and interprets non-English comments

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • 林乔安妮
  • A fashion stylist GPT offering outfit suggestions for various scenarios.

  • 1Panel-dev
  • 💬 MaxKB is a ready-to-use AI chatbot that integrates Retrieval-Augmented Generation (RAG) pipelines, supports robust workflows, and provides advanced MCP tool-use capabilities.

  • ShrimpingIt
  • Micropython I2C-based manipulation of the MCP series GPIO expander, derived from Adafruit_MCP230xx

  • GLips
  • MCP server to provide Figma layout information to AI coding agents like Cursor

  • Dhravya
  • Collection of apple-native tools for the model context protocol.

  • Mintplex-Labs
  • The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.

  • open-webui
  • A simple, secure MCP-to-OpenAPI proxy server

  • adafruit
  • Python code to use the MCP3008 analog to digital converter with a Raspberry Pi or BeagleBone black.

  • idosal
  • Put an end to hallucinations! GitMCP is a free, open-source, remote MCP server for any GitHub project

    Reviews

    1 (1)
    Avatar
    user_AfIUauy8
    2025-04-17

    I've been using mcp-mongo-server for a while now and it has significantly streamlined my workflow. Created by kiliczsh, this server is incredibly reliable and well-documented. The seamless integration with MongoDB is a game-changer, allowing me to manage my databases efficiently. Highly recommend checking it out at https://github.com/kiliczsh/mcp-mongo-server.