MongoDB MCP server

Enables direct interaction with MongoDB databases for querying, modifying, and managing collections, documents, and indexes using MongoDB's native query syntax.
Back to servers
Setup instructions
Provider
Vivek
Release date
Mar 19, 2025
Language
TypeScript

This MCP server allows Large Language Models like Claude to interact directly with MongoDB databases through natural language. You can query collections, inspect schemas, and manage data without writing MongoDB code directly.

Quick Start

To use the MongoDB MCP Server with Claude Desktop, you need to add configuration to your Claude Desktop config file.

Prerequisites

  • Node.js 18+
  • npx
  • MCP Client (Claude Desktop App)

Configuration

Add this to your Claude Desktop configuration file:

MacOS:

~/Library/Application\ Support/Claude/claude_desktop_config.json

Windows:

%APPDATA%/Claude/claude_desktop_config.json

Add the following JSON:

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

Replace <username>, <password>, <host>, <port>, and <database> with your MongoDB connection details.

Installing via Smithery

For automatic installation with Claude Desktop:

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

Test Sandbox Setup

If you don't have a MongoDB server to connect to, you can create a sample sandbox:

  1. Start MongoDB using Docker Compose:
docker-compose up -d
  1. Seed the database with test data:
npm run seed
  1. Configure Claude Desktop for local testing:
{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": [
        "dist/index.js",
        "mongodb://root:example@localhost:27017/test?authSource=admin"
      ]
    }
  }
}

Using With Claude

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

Basic Operations

What collections are available in the database?
Show me the schema for the users collection
Find all users in San Francisco

Advanced Queries

Find all electronics products that are in stock and cost less than $1000
Show me all orders from the user [email protected]
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

Available Tools

The server provides the following tools for database interaction:

Query Tools

  • find: Query documents with filtering and projection
  • listCollections: List available collections
  • insertOne: Insert a single document
  • updateOne: Update a single document
  • deleteOne: Delete a single document

Index Tools

  • createIndex: Create a new index
  • dropIndex: Remove an index
  • indexes: List indexes for a collection

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mongodb" '{"command":"npx","args":["mongo-mcp","mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later