MongoDB MCP Server
This repository implements an MCP (Model Context Protocol) server that connects to a MongoDB database and exposes operations for managing databases, collections, documents, indexes, and bulk operations. It uses Node.js, TypeScript, and the MCP SDK, e
What is MongoDB MCP Server?
MongoDB MCP Server is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to this repository implements an mcp (model context protocol) server that connects to a mongodb database and exposes operations for managing databases, collections, documents, indexes, and bulk operation...
This repository implements an MCP (Model Context Protocol) server that connects to a MongoDB database and exposes operations for managing databases, collections, documents, indexes, and bulk operations. It uses Node.js, TypeScript, and the MCP SDK, e
This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- connect
- list-collections
- list-databases
- collection-indexes
- create-index
Use Cases
Maintainer
Works with
Installation
NPM
npx -y mongodb-mcp-serverManual Installation
npx -y mongodb-mcp-serverConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use MongoDB MCP Server
The MongoDB MCP Server is the official MCP integration maintained by MongoDB, Inc. that gives AI assistants direct access to MongoDB databases and MongoDB Atlas clusters through natural language. It exposes a comprehensive set of tools covering CRUD operations, aggregation pipelines, index management, schema inference, Atlas cluster administration, database user management, IP access lists, and Performance Advisor recommendations. Development teams use it to let Claude and other MCP clients query, update, and manage MongoDB data without writing driver code.
Prerequisites
- Node.js v22.13.0 or later
- A running MongoDB instance (local, Docker, or cloud) with a connection string, OR MongoDB Atlas account credentials
- For Atlas management features: a MongoDB Atlas service account with `MDB_MCP_API_CLIENT_ID` and `MDB_MCP_API_CLIENT_SECRET`
- An MCP-compatible client such as Claude Desktop, VS Code, or Cursor
Verify Node.js version
The server requires Node.js v22.13.0 or later. Check your version and upgrade if needed.
node --versionTest the server with npx
Run the server directly to confirm it starts. In read-only mode it is safe to run against any database without risk of modifications.
npx -y mongodb-mcp-server@latest --readOnlyConfigure Claude Desktop
Add the MongoDB MCP server to your Claude Desktop configuration file. Store your connection string as an environment variable rather than hardcoding it.
Restart Claude Desktop
Restart Claude Desktop to load the new server configuration. Verify that the MongoDB tools appear in the tool list.
Connect to your database
Ask Claude to connect to your MongoDB instance. The server also supports switching connections mid-session.
MongoDB MCP Server Examples
Client configuration
Claude Desktop configuration for the official MongoDB MCP server using a local connection string. For Atlas API access, add `MDB_MCP_API_CLIENT_ID` and `MDB_MCP_API_CLIENT_SECRET` to the env block.
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017"
}
}
}
}Prompts to try
Sample prompts for using the MongoDB MCP server with Claude Desktop.
- "List all databases and the collections in the 'ecommerce' database."
- "Find the 10 most recent orders in the orders collection where status is 'pending'."
- "What indexes exist on the users collection? Are there any missing indexes for the queries I'm running?"
- "Insert a new product document into the products collection with these fields: [name, price, category]."
- "Run an aggregation to calculate total revenue per product category for the last 30 days."
- "Show me the schema of the events collection by sampling 100 documents."Troubleshooting MongoDB MCP Server
Connection refused when using `mongodb://localhost:27017`
Verify MongoDB is running locally with `mongosh --eval 'db.runCommand({ping:1})'`. If using Docker, ensure the container port is mapped: `docker run -p 27017:27017 mongo`. For Atlas, use the full `mongodb+srv://` connection string from the Atlas console.
Atlas API operations return 401 Unauthorized
Ensure `MDB_MCP_API_CLIENT_ID` and `MDB_MCP_API_CLIENT_SECRET` are set to a valid Atlas service account. The service account must be assigned at the organization or project level with the minimum required role (e.g., `Project Read Only` for read operations). Generate new credentials in Atlas under Access Manager → Service Accounts.
Write operations are rejected even though `--readOnly` is not set
Check whether `MDB_MCP_READ_ONLY=true` is set in the environment. Remove that variable or set it to `false` to allow write operations. Also verify the MongoDB user in the connection string has write permissions on the target database.
Frequently Asked Questions about MongoDB MCP Server
What is MongoDB MCP Server?
MongoDB MCP Server is a Model Context Protocol (MCP) server that this repository implements an mcp (model context protocol) server that connects to a mongodb database and exposes operations for managing databases, collections, documents, indexes, and bulk operations. it uses node.js, typescript, and the mcp sdk, e It connects AI assistants to external tools and data sources through a standardized interface.
How do I install MongoDB MCP Server?
Install via npm with the command: npx -y mongodb-mcp-server. Then add the server configuration to your AI client's JSON config file (e.g., claude_desktop_config.json or .cursor/mcp.json).
Which AI clients work with MongoDB MCP Server?
MongoDB MCP Server works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is MongoDB MCP Server free to use?
Yes, MongoDB MCP Server is open source and available under the Apache-2.0 license. You can use it freely in both personal and commercial projects.
MongoDB MCP Server Alternatives — Similar Databases Servers
Looking for alternatives to MongoDB MCP Server? Here are other popular databases servers you can use with Claude, Cursor, and VS Code.
Excelize
★ 20.6kGo language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
MCP Toolbox for Databases
★ 15.3kOpen source MCP server specializing in easy, fast, and secure tools for Databases.
DBHub
★ 2.8kA universal database gateway MCP server that enables AI assistants to connect to and query multiple databases (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite) with support for schema exploration, SQL execution, and secure connections via SSH tunnels.
Tabularis
★ 2.1kA lightweight, cross-platform database client for developers. Supports MySQL, PostgreSQL and SQLite. Hackable with plugins. Built for speed, security, and aesthetics.
Postgres AI Guide
★ 1.7kMCP server and Claude plugin for Postgres skills and documentation. Helps AI coding tools generate better PostgreSQL code.
Anyquery
★ 1.7k🏎️ 🏠 ☁️ - Query more than 40 apps with one binary using SQL. It can also connect to your PostgreSQL, MySQL, or SQLite compatible database. Local-first and private by design.
Browse More Databases MCP Servers
Explore all databases servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up MongoDB MCP Server in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use MongoDB MCP Server?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.