mongodb.com
mongodb.com logo

MongoDB

Query and analyze MongoDB databases.

Created byApr 22, 2025

MCP MongoDB Server


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

Key Features

Smart ObjectId Handling

  • Intelligent conversion between string IDs and MongoDB ObjectId
  • Configurable with objectIdMode parameter:

Flexible Configuration

  • Environment Variables:
  • Command-line Options:

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:
  • Write Operations (when not in read-only mode):

LLM Integration

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

Installation

Global Installation

For Development

Usage

Basic Usage

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:
Using environment variables in Claude Desktop configuration:
Using environment variables with Docker:

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:

Environment Variables Approach:

GitHub Package Usage:

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:

Cursor Configuration

For Cursor, add the server configuration to your settings:
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:
Using mcp-get:

Available Tools

Query Operations

  • query: Execute MongoDB queries
  • aggregate: Run aggregation pipelines
  • count: Count matching documents

Write Operations

  • update: Modify documents
  • insert: Add new documents
  • createIndex: Create collection indexes

System Operations

  • serverInfo: Get MongoDB server details

Debugging

Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:
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.

MCP MongoDB Server


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

Key Features

Smart ObjectId Handling

  • Intelligent conversion between string IDs and MongoDB ObjectId
  • Configurable with objectIdMode parameter:

Flexible Configuration

  • Environment Variables:
  • Command-line Options:

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:
  • Write Operations (when not in read-only mode):

LLM Integration

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

Installation

Global Installation

For Development

Usage

Basic Usage

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:
Using environment variables in Claude Desktop configuration:
Using environment variables with Docker:

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:

Environment Variables Approach:

GitHub Package Usage:

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:

Cursor Configuration

For Cursor, add the server configuration to your settings:
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:
Using mcp-get:

Available Tools

Query Operations

  • query: Execute MongoDB queries
  • aggregate: Run aggregation pipelines
  • count: Count matching documents

Write Operations

  • update: Modify documents
  • insert: Add new documents
  • createIndex: Create collection indexes

System Operations

  • serverInfo: Get MongoDB server details

Debugging

Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector for better visibility:
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.