MCP MongoDB Server

MCP MongoDB Server

A Model Context Protocol server for LLM interaction with MongoDB databases.

267
Stars
50
Forks
267
Watchers
2
Issues
MCP MongoDB Server enables large language models to interact with MongoDB databases through the standardized Model Context Protocol interface. It provides schema inspection, document querying, aggregation, and write operations with intelligent ObjectId handling and flexible read-only configurations. Designed for seamless integration with tools like Claude Desktop, it offers collection completions, schema inference, and robust support for both development and production environments.

Key Features

Standardized Model Context Protocol (MCP) server interface
Intelligent ObjectId conversion and management
Configurable read-only mode for safety and production use
Collection schema inference and analysis
Support for document querying, aggregation, and index creation
Integration with Claude Desktop and other LLM platforms
Environment variable and CLI based configuration
Aggregation pipeline execution
Detailed collection completions for LLMs
Docker and CI/CD friendly deployment

Use Cases

Enabling LLMs to query and analyze MongoDB databases
Providing schema-level data insights to AI assistants
Secure, read-only integration with production databases
Facilitating AI research and prototyping with live data
Automating MongoDB operations in CI/CD environments
Powering generative AI applications with real database context
Safe database access and analysis in desktop AI tools
Data exploration and collection discovery for AI agents
Rapid data ingestion and contextual analysis for AI pipelines
Hands-off management of ObjectId fields for AI-driven workflows

README

MCP MongoDB Server


NPM Version NPM Downloads NPM License smithery badge Verified on MseeP

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

bash
npm install -g mcp-mongo-server

For Development

bash
# 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

bash
# 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:

bash
# 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:

json
{
  "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:

bash
# Build
docker build -t mcp-mongo-server .

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

# or edit docker-compose.yml and run
docker-compose up -d

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:

json
{
  "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:

json
{
  "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:

json
{
  "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:

json
{
  "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:

json
{
  "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:

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

Using mcp-get:

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

Available Tools

Query Operations

  • query: Execute MongoDB queries

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

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

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

Write Operations

  • update: Modify documents

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

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

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

System Operations

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

Debugging

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

bash
npm run inspector

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

Running evals

The evals package loads an mcp client that then runs the index.ts file, so there is no need to rebuild between tests. You can load environment variables by prefixing the npx command. Full documentation can be found here.

bash
OPENAI_API_KEY=your-key  npx mcp-eval src/evals/evals.ts src/schemas/tools.ts

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.

Star History

Star History Chart

Repository Owner

kiliczsh
kiliczsh

User

Repository Details

Language TypeScript
Default Branch main
Size 98 KB
Contributors 7
License MIT License
MCP Verified Nov 12, 2025

Programming Languages

TypeScript
93.93%
JavaScript
4.49%
Dockerfile
1.58%

Tags

Topics

antrophic claude claude-desktop cline cursor mcp model-context-protocol mongo mongodb windsurf

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • MongoDB MCP Server

    MongoDB MCP Server

    A Model Context Protocol server for enabling LLM interaction with MongoDB databases.

    MongoDB MCP Server empowers language models to interface directly with MongoDB databases using the Model Context Protocol (MCP). It enables natural language querying and management of collections, documents, and indexes. Users can inspect database schemas, execute document operations, and manage indexes seamlessly. The tool integrates with clients like Claude Desktop for conversational database management.

    • 172
    • MCP
    • QuantGeekDev/mongo-mcp
  • MCP Server for Milvus

    MCP Server for Milvus

    Bridge Milvus vector database with AI apps using Model Context Protocol (MCP).

    MCP Server for Milvus enables seamless integration between the Milvus vector database and large language model (LLM) applications via the Model Context Protocol. It exposes Milvus functionality to external LLM-powered tools through both stdio and Server-Sent Events communication modes. The solution is compatible with MCP-enabled clients such as Claude Desktop and Cursor, supporting easy access to relevant vector data for enhanced AI workflows. Configuration is flexible through environment variables or command-line arguments.

    • 196
    • MCP
    • zilliztech/mcp-server-milvus
  • Multi-Database MCP Server (by Legion AI)

    Multi-Database MCP Server (by Legion AI)

    Unified multi-database access and AI interaction server with MCP integration.

    Multi-Database MCP Server enables seamless access and querying of diverse databases via a unified API, with native support for the Model Context Protocol (MCP). It supports popular databases such as PostgreSQL, MySQL, SQL Server, and more, and is built for integration with AI assistants and agents. Leveraging the MCP Python SDK, it exposes databases as resources, tools, and prompts for intelligent, context-aware interactions, while delivering zero-configuration schema discovery and secure credential management.

    • 76
    • MCP
    • TheRaLabs/legion-mcp
  • Teamwork MCP Server

    Teamwork MCP Server

    Seamless Teamwork.com integration for Large Language Models via the Model Context Protocol

    Teamwork MCP Server is an implementation of the Model Context Protocol (MCP) that enables Large Language Models to interact securely and programmatically with Teamwork.com. It offers standardized interfaces, including HTTP and STDIO, allowing AI agents to perform various project management operations. The server supports multiple authentication methods, an extensible toolset architecture, and is designed for production deployments. It provides read-only capability for safe integrations and robust observability features.

    • 11
    • MCP
    • Teamwork/mcp
  • OpsLevel MCP Server

    OpsLevel MCP Server

    Read-only MCP server for integrating OpsLevel data with AI tools.

    OpsLevel MCP Server implements the Model Context Protocol to provide AI tools with a secure way to access and interact with OpsLevel account data. It supports read-only operations for a wide range of OpsLevel resources such as actions, campaigns, checks, components, documentation, domains, and more. The tool is compatible with popular environments including Claude Desktop and VS Code, enabling easy integration via configuration and API tokens. Installation options include Homebrew, Docker, and standalone binaries.

    • 8
    • MCP
    • OpsLevel/opslevel-mcp
  • mcp-graphql

    mcp-graphql

    Enables LLMs to interact dynamically with GraphQL APIs via Model Context Protocol.

    mcp-graphql provides a Model Context Protocol (MCP) server that allows large language models to discover and interact with GraphQL APIs. The implementation facilitates schema introspection, exposes the GraphQL schema as a resource, and enables secure query and mutation execution based on configuration. It supports configuration through environment variables, automated or manual installation options, and offers flexibility in using local or remote schema files. By default, mutation operations are disabled for security, but can be enabled if required.

    • 319
    • MCP
    • blurrah/mcp-graphql
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results