How to Install and Configure MongoDB MCP Server

INEZA FELIN-MICHEL

INEZA FELIN-MICHEL

20 June 2025

How to Install and Configure MongoDB MCP Server

In the ever-evolving landscape of software development, the integration of Artificial Intelligence is no longer a futuristic concept but a present-day reality. AI-powered tools are rapidly becoming indispensable for developers, streamlining workflows, and enhancing productivity. Recognizing this trend, MongoDB has introduced a groundbreaking tool that bridges the gap between your database and AI: the MongoDB Model Context Protocol (MCP) Server. This tutorial provides a comprehensive, step-by-step guide to installing and configuring the MongoDB MCP Server, empowering you to leverage the full potential of AI in your development environment.

💡
Want a great API Testing tool that generates beautiful API Documentation?

Want an integrated, All-in-One platform for your Developer Team to work together with maximum productivity?

Apidog delivers all your demands, and replaces Postman at a much more affordable price!
button

What is the MongoDB MCP Server?

The MongoDB MCP Server is a powerful new tool designed to connect your MongoDB deployments with a variety of AI-powered clients that support the Model Context Protocol (MCP). Whether you are using MongoDB Atlas, the fully-managed cloud database, or a self-hosted Community or Enterprise Advanced edition, the MCP Server enables seamless interaction with your data using natural language. This means you can perform a wide range of database operations, from simple data queries to complex administrative tasks, all through intuitive, conversational commands within your favorite AI development tools.

The MCP is an open standard, initially introduced by Anthropic, that is rapidly gaining traction for its ability to create a standardized communication layer between AI agents and diverse data systems. By implementing this protocol, MongoDB is ensuring that its users can stay at the forefront of AI-driven development. The MCP Server facilitates a two-way communication channel, allowing you to not only query your data but also provide your Large Language Models (LLMs) with the most current and contextually relevant information from your database. This is a game-changer for tasks like data exploration, database administration, and generating context-aware code.

The MongoDB MCP Server supports a growing ecosystem of MCP clients, including:

Let's get started!

Prerequisites

Before we dive into the installation process, there are a few prerequisites you need to have in place:

Installation and Configuration

The installation and configuration process for the MongoDB MCP Server varies slightly depending on the MCP client you are using. The core of the process involves adding a JSON configuration to your client's settings file that tells it how to launch and communicate with the MCP server.

The primary command to run the server is npx -y mongodb-mcp-server. The -y flag automatically confirms the installation of the package if it's not already present.

Setting up in Cursor

Cursor is an AI-first code editor that is rapidly gaining popularity. Here’s how you can set up the MongoDB MCP Server in Cursor:

  1. Open Cursor's Settings: Launch Cursor and click on the gear icon in the top-right corner of the window to open the settings.
  2. Navigate to the MCP Section: In the settings panel on the left, click on "MCP".
  3. Add a New Global MCP Server: Click the "Add new global MCP server" button. This will open a JSON configuration file.
  4. Enter the Configuration: Copy and paste the following JSON configuration into the file. You will need to customize this with your connection details.

<!-- end list -->JSON

{
  "mongodb": {
    "command": "npx",
    "args": [
      "-y",
      "mongodb-mcp-server"
    ],
    "environments": [
      {
        "name": "ATLAS_API_CLIENT_ID",
        "value": "your-atlas-api-client-id"
      },
      {
        "name": "ATLAS_API_CLIENT_SECRET",
        "value": "your-atlas-api-client-secret"
      }
    ]
  }
}

If you are using a connection string instead of Atlas API credentials, your configuration will look like this:JSON

{
  "mongodb": {
    "command": "npx",
    "args": [
      "-y",
      "mongodb-mcp-server",
      "--connectionString",
      "your-mongodb-connection-string"
    ]
  }
}
  1. Save the Configuration: Save the file. Cursor will now be able to use your new MongoDB MCP Server.

With the server configured, you can now interact with your database using natural language within Cursor. If you've used your Atlas API credentials, you'll have access to a rich set of Atlas-specific tools, allowing you to create free clusters, manage access lists, create database users, and much more. If you've used a connection string, you'll have access to tools for database management, such as listing databases and collections, managing indexes, and performing CRUD (Create, Read, Update, Delete) operations.

Setting up in Claude Desktop

If you are a user of Anthropic's Claude, you can integrate the MongoDB MCP Server directly into the Claude desktop application.

  1. Open the Configuration File: Start the Claude Desktop application, then navigate to Settings > Developer > Edit Config. This will open the claude_desktop_config.json file in your default text editor. The location of this file is typically:
  1. Add the MCP Server Configuration: Add the following configuration to the mcpServers object in the JSON file.

<!-- end list -->JSON

{
  "mcpServers": {
    "MongoDB": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString",
        "mongodb+srv://<user-name>:<password>@<cluster-name>.mongodb.net/test"
      ]
    }
  }
}

Make sure to replace the placeholder connection string with your actual connection string.

  1. Restart Claude Desktop: Close and restart the Claude Desktop application.
  2. Verify the Server: Click on the hammer icon in Claude Desktop. The MongoDB MCP Server should now be listed as an available tool.

Setting up in Visual Studio Code with GitHub Copilot

For the millions of developers who use Visual Studio Code, the MongoDB MCP Server can be integrated with GitHub Copilot to bring natural language database interaction to your favorite IDE.

  1. Open the Command Palette: Open VS Code and press Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the command palette.
  2. Add a New MCP Server: Type "mcp" into the command palette and select "MCP: Add Servers".
  3. Choose Command Standard I/O: Select "Command Standard I/O" as the server type.
  4. Enter the Command: Enter the command npx -y mongodb-mcp-server and give your server a name, for example, "mongodb".
  5. Configure in settings.json: This will open your settings.json file. Here, you can add your arguments and environment variables. For example, to use a connection string:

<!-- end list -->JSON

"mcp.servers": {
  "mongodb": {
    "command": "npx",
    "args": [
      "-y",
      "mongodb-mcp-server",
      "--connectionString",
      "your-mongodb-connection-string"
    ]
  }
}

Or, to use Atlas API credentials:JSON

"mcp.servers": {
  "mongodb": {
    "command": "npx",
    "args": [
      "-y",
      "mongodb-mcp-server"
    ],
    "options": {
      "env": {
        "ATLAS_API_CLIENT_ID": "your-atlas-api-client-id",
        "ATLAS_API_CLIENT_SECRET": "your-atlas-api-client-secret"
      }
    }
  }
}
  1. Start the Server: You can start the server by clicking the "Start" button that appears above the server name in your settings.json file, or by opening the command palette, searching for "MCP: List Servers", selecting your server, and then selecting "Start Server".

Once the server is running, you can use the GitHub Copilot agent mode to interact with your MongoDB Atlas environment. You can ask it to list your projects, create new clusters, manage users, and much more, all from within VS Code.

Advanced Configuration

The MongoDB MCP Server offers several advanced configuration options to tailor its behavior to your specific needs.

Read-Only Mode

For added safety, especially when connecting to production databases, you can run the server in read-only mode. This will prevent any write operations, such as creating, updating, or deleting documents. You can enable read-only mode using a command-line argument:

npx mongodb-mcp-server --readOnly

Or by setting an environment variable:

export MDB_MCP_READ_ONLY=true

Disabling Specific Tools

You can disable specific tools to restrict the server's capabilities. This is useful for security or for simplifying the available commands. You can disable tools using the --disabledTools command-line argument, followed by a space-separated list of tool names.

npx mongodb-mcp-server --disabledTools create update delete atlas collectionSchema

Alternatively, you can use the MDB_MCP_DISABLED_TOOLS environment variable with a comma-separated list of tool names.

export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema"

Telemetry

By default, the MongoDB MCP Server collects anonymous usage data to help improve the product. If you wish to disable this, you can use the --telemetry disabled command-line argument or the MDB_MCP_TELEMETRY=disabled environment variable.

Docker Installation

For those who prefer a containerized environment, the MongoDB MCP Server can be run in a Docker container. This provides isolation and removes the need for a local Node.js installation.

To run the server with a connection string:

docker run --rm -i -e MDB_MCP_CONNECTION_STRING="your-mongodb-connection-string" mongodb/mongodb-mcp-server:latest

To run with Atlas API credentials:

docker run --rm -i -e MDB_MCP_API_CLIENT_ID="your-atlas-api-client-id" -e MDB_MCP_API_CLIENT_SECRET="your-atlas-api-client-secret" mongodb/mongodb-mcp-server:latest

You would then configure your MCP client to use the docker command instead of npx. For example, in Claude Desktop:JSON

{
  "mcpServers": {
    "MongoDB": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        "MDB_MCP_API_CLIENT_ID=your-atlas-api-client-id",
        "-e",
        "MDB_MCP_API_CLIENT_SECRET=your-atlas-api-client-secret",
        "mongodb/mongodb-mcp-server:latest"
      ]
    }
  }
}

Conclusion

The MongoDB MCP Server represents a significant step forward in the integration of AI and databases. By providing a standardized way for AI clients to interact with MongoDB, it opens up a world of possibilities for developers. From natural language querying and data exploration to AI-assisted database administration and code generation, the MCP Server is set to become an essential tool in the modern developer's toolkit.

This tutorial has provided a comprehensive guide to getting started with the MongoDB MCP Server. By following these steps, you can quickly and easily connect your MongoDB deployments to your favorite AI tools and start reaping the benefits of AI-powered development. As this is a new and evolving technology, be sure to check the official MongoDB documentation and the GitHub repository for the latest updates and features. The future of database interaction is here, and with the MongoDB MCP Server, you are at the cutting edge.

💡
Want a great API Testing tool that generates beautiful API Documentation?

Want an integrated, All-in-One platform for your Developer Team to work together with maximum productivity?

Apidog delivers all your demands, and replaces Postman at a much more affordable price!
button

Explore more

Why I Love Stripe Docs (API Documentation Best Practices)

Why I Love Stripe Docs (API Documentation Best Practices)

As a developer, I’ve had my fair share of late nights fueled by frustration and bad documentation. I think we all have. I can still vividly recall the cold sweat of trying to integrate a certain legacy payment processor years ago. It was a nightmare of fragmented guides, conflicting API versions, and a dashboard that felt like a labyrinth designed by a committee that hated joy. After hours of wrestling with convoluted SOAP requests and getting absolutely nowhere, I threw in the towel. A colleagu

20 June 2025

How to Use graphql-codegen, A Beginners' Guide

How to Use graphql-codegen, A Beginners' Guide

In the ever-evolving landscape of web development, GraphQL has emerged as a powerful alternative to traditional REST APIs, offering clients the ability to request precisely the data they need. However, this flexibility can introduce a new set of challenges, particularly when it comes to maintaining type safety between the frontend and backend. This is where graphql-codegen comes in, a revolutionary tool that automates the generation of typed code from your GraphQL schema, supercharging your deve

20 June 2025

How to Use Sentry MCP Server for Debugging

How to Use Sentry MCP Server for Debugging

Developers are constantly under pressure to deliver high-quality applications with fewer bugs. While tools like Sentry have become indispensable for error and performance monitoring, the process of debugging can still be a time-consuming and complex endeavor. However, a new paradigm is emerging, one that promises to revolutionize the way we debug our applications by seamlessly integrating the power of artificial intelligence into our development workflows. At the forefront of this transformation

20 June 2025

Practice API Design-first in Apidog

Discover an easier way to build and use APIs