MongoDB MCP server

Integrates with MongoDB databases to enable direct querying, inserting, updating, and managing data collections without leaving the conversation interface.
Back to servers
Provider
Alex Andrushevich
Release date
Mar 18, 2025
Language
TypeScript

This MCP server enables LLMs like Claude to interact directly with MongoDB databases through natural language. It allows querying collections, inspecting schemas, and managing data without writing complex database queries.

Installation

Prerequisites

  • Node.js 18+
  • npx
  • A MongoDB database connection URL
  • Claude Desktop App

Installation via Smithery

The easiest way to install MongoDB MCP Server for Claude Desktop is using Smithery:

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

Manual Setup

If you prefer to set up manually, add this configuration to your Claude Desktop config file:

MacOS:

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

Windows:

%APPDATA%/Claude/claude_desktop_config.json

Add the following configuration (replace the MongoDB connection string with your own):

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

Setting Up a Test Sandbox

If you don't have a MongoDB server but want to test the MCP server:

  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 development:
{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": [
        "dist/index.js",
        "mongodb://root:example@localhost:27017/test?authSource=admin"
      ]
    }
  }
}

Usage

Once installed, you can interact with your MongoDB database by asking Claude natural language questions and commands.

Basic Queries

Try these example prompts with Claude:

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

Advanced Queries

You can perform more complex queries like:

  • "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"

Managing Indexes

The MCP server allows you to manage database indexes:

  • "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

You can also modify data with commands like:

  • "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 MCP server provides these MongoDB interaction tools:

Query Operations

  • Find documents with filtering and projection
  • List available collections
  • Insert a single document
  • Update a single document
  • Delete a single document

Index Operations

  • Create a new index
  • Remove an index
  • List indexes for a collection

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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