MongoDB
A Model Context Protocol (MCP) server that enables LLMs to interact directly with MongoDB databases. Query collections, inspect schemas, and manage data seamlessly through natural language.
What is MongoDB?
MongoDB is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to model context protocol (mcp) server that enables llms to interact directly with mongodb databases. query collections, inspect schemas, and manage data seamlessly through natural language.
A Model Context Protocol (MCP) server that enables LLMs to interact directly with MongoDB databases. Query collections, inspect schemas, and manage data seamlessly through natural language.
This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- A Model Context Protocol (MCP) server that enables LLMs to i
Use Cases
Maintainer
Works with
Installation
NPM
npx -y mongodbManual Installation
npx -y mongodbConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use MongoDB
The MongoDB MCP server (mcp-mongo-server) lets LLMs interact directly with MongoDB databases using natural language. It supports schema inference from document samples, full query and aggregation pipeline execution, optional explain plans, write operations (insert, update, index creation), and smart ObjectId handling. Developers and data engineers use it to let Claude explore unfamiliar database schemas, prototype queries, inspect collection statistics, and perform ad-hoc data operations without switching to a separate MongoDB client.
Prerequisites
- A running MongoDB instance (local, Docker, or MongoDB Atlas)
- A valid MongoDB connection URI (e.g. mongodb://localhost:27017/dbname or mongodb+srv://...)
- Node.js 18+ (for npx)
- Claude Desktop or another MCP-compatible client
Confirm your MongoDB connection URI
Gather the connection string for your MongoDB instance. For local instances the default is mongodb://localhost:27017/yourDatabase. For Atlas, copy the connection string from the Atlas dashboard and include your username and password.
Test the connection from the command line
Run the server once manually with your URI to verify the connection works before configuring Claude Desktop.
npx -y mcp-mongo-server mongodb://localhost:27017/myDatabaseAdd the server to Claude Desktop configuration
Add mcp-mongo-server to your Claude Desktop config. Pass the MongoDB URI via the MCP_MONGODB_URI environment variable.
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "mcp-mongo-server"],
"env": {
"MCP_MONGODB_URI": "mongodb://localhost:27017/myDatabase"
}
}
}
}Optional: enable read-only mode
Set MCP_MONGODB_READONLY to 'true' or pass --read-only to prevent any write operations. Recommended when connecting to production databases.
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "mcp-mongo-server", "--read-only"],
"env": {
"MCP_MONGODB_URI": "mongodb://user:password@host:27017/myDatabase"
}
}
}
}Restart Claude Desktop and explore your database
Restart Claude Desktop. Ask Claude to list collections, describe a schema, or run a query against your database.
MongoDB Examples
Client configuration
Claude Desktop configuration for the MongoDB MCP server using an environment variable for the connection URI.
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "mcp-mongo-server"],
"env": {
"MCP_MONGODB_URI": "mongodb://localhost:27017/myDatabase"
}
}
}
}Prompts to try
Example prompts for exploring and querying MongoDB through Claude.
- "List all collections in the database and describe their schemas"
- "Find all users who signed up in the last 30 days and have not verified their email"
- "Run an aggregation to show total revenue per product category for 2024"
- "Show me the explain plan for this query: db.orders.find({ status: 'pending' })"
- "Insert a test document into the logs collection with a timestamp and message field"
- "Create an index on the email field in the users collection"Troubleshooting MongoDB
Connection refused — cannot connect to MongoDB
Verify MongoDB is running with `mongosh` or `mongo` in a terminal. For local instances confirm it listens on port 27017. For Atlas, ensure your current IP address is whitelisted in the Atlas Network Access settings.
Authentication failed with credentials in the URI
URL-encode any special characters in the username or password (e.g. @ becomes %40, # becomes %23). Test the URI directly with `mongosh 'mongodb://user:pass@host/db'` to isolate authentication issues.
Write operation rejected even though read-only mode is not set
Check that MCP_MONGODB_READONLY is not accidentally set to 'true' in your environment. Also verify the MongoDB user in the connection URI has write permissions on the target database.
Frequently Asked Questions about MongoDB
What is MongoDB?
MongoDB is a Model Context Protocol (MCP) server that model context protocol (mcp) server that enables llms to interact directly with mongodb databases. query collections, inspect schemas, and manage data seamlessly through natural language. It connects AI assistants to external tools and data sources through a standardized interface.
How do I install MongoDB?
Install via npm with the command: npx -y mongodb. 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?
MongoDB works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is MongoDB free to use?
Yes, MongoDB is open source and available under the MIT License license. You can use it freely in both personal and commercial projects.
MongoDB Alternatives — Similar Databases Servers
Looking for alternatives to MongoDB? 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 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?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.