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 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!
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:
- Windsurf: An AI-native code editor where the MCP server is available out-of-the-box.
- Cursor: A popular AI-powered code editor.
- GitHub Copilot in Visual Studio Code: Bringing the power of your database to the world's most popular IDE.
- Anthropic's Claude: Interact with your database directly from the Claude desktop application.
Let's get started!

Prerequisites
Before we dive into the installation process, there are a few prerequisites you need to have in place:
- Node.js and npx: The MongoDB MCP Server is a Node.js application and is typically installed and run using
npx
, the Node.js package runner. You'll need Node.js version 18 or higher installed on your system. You can verify your Node.js version by opening a terminal or command prompt and runningnode -v
. - MongoDB Connection String or Atlas API Credentials: To connect to your database, the MCP Server needs either a standard MongoDB connection string or API credentials for your MongoDB Atlas account.
- Connection String: This is the standard URI format for connecting to a MongoDB instance. It includes the username, password, host, port, and database name.
- Atlas API Credentials: If you are using MongoDB Atlas, you can create a service account with the necessary permissions and use the generated API Client ID and Client Secret for authentication. This method is required for using the Atlas-specific tools.
- An MCP Client: You'll need one of the supported MCP clients installed, such as Cursor, Claude Desktop, or Visual Studio Code with the GitHub Copilot extension.
- Docker (Optional): If you prefer to run the MCP Server in a containerized environment, you will need Docker and Docker Compose installed. This is particularly useful for local sandbox testing and for avoiding a local Node.js installation.
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:
- Open Cursor's Settings: Launch Cursor and click on the gear icon in the top-right corner of the window to open the settings.
- Navigate to the MCP Section: In the settings panel on the left, click on "MCP".
- Add a New Global MCP Server: Click the "Add new global MCP server" button. This will open a JSON configuration file.
- 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"
]
}
}
- 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.
- Open the Configuration File: Start the Claude Desktop application, then navigate to
Settings > Developer > Edit Config
. This will open theclaude_desktop_config.json
file in your default text editor. The location of this file is typically:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%/Claude/claude_desktop_config.json
- 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.
- Restart Claude Desktop: Close and restart the Claude Desktop application.
- 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.
- Open the Command Palette: Open VS Code and press
Ctrl+Shift+P
(orCmd+Shift+P
on macOS) to open the command palette. - Add a New MCP Server: Type "mcp" into the command palette and select "MCP: Add Servers".
- Choose Command Standard I/O: Select "Command Standard I/O" as the server type.
- Enter the Command: Enter the command
npx -y mongodb-mcp-server
and give your server a name, for example, "mongodb". - 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"
}
}
}
}
- 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 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!