MongoDB MCP Server in Cursor IDE: Query Collections & Debug Schemas (2026)
Connect MongoDB to Cursor IDE via MCP and query your collections, inspect schemas, and debug data issues directly while writing code. Works with Atlas and self-hosted MongoDB.
MongoDB MCP Server Setup for Cursor IDE (2026)
The MongoDB MCP server lets Cursor's AI query your collections, inspect document schemas, run aggregation pipelines, and check indexes — all without leaving your editor. Whether you're working against MongoDB Atlas or a self-hosted instance, this guide covers the full setup.
What You Can Do with MongoDB + Cursor MCP
Once connected, you can ask Cursor things like:
This removes the constant tab-switching between editor and MongoDB Compass, Robo 3T, or the Atlas Data Explorer.
Prerequisites
Step 1: Get Your MongoDB Connection String
MongoDB Atlas
1. Go to your Atlas project → Database → Click Connect
2. Select Connect your application
3. Copy the connection string — it looks like:
mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/
4. Replace
with your actual database user passwordSelf-Hosted MongoDB
Your connection string is typically:
mongodb://username:password@localhost:27017/
Or for a replica set:
mongodb://username:password@host1:27017,host2:27017/?replicaSet=rs0
Security tip: Create a dedicated read-only database user for MCP access. In Atlas, go to Database Access → Add New Database User and assign the built-in readAnyDatabase role.
Step 2: Add to Your Cursor mcp.json
MongoDB maintains an official MCP server. Add it to ~/.cursor/mcp.json:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "@mongodb-js/mongodb-mcp-server"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/"
}
}
}
}
Replace the connection string with your actual URI.
Do not commit this file to git. Add .cursor/mcp.json to your .gitignore, or use environment variable interpolation:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": ["-y", "@mongodb-js/mongodb-mcp-server"],
"env": {
"MDB_MCP_CONNECTION_STRING": "${MONGODB_URI}"
}
}
}
}
This pulls the value from your shell environment variable MONGODB_URI.
On Windows, use the full npx path if the server doesn't load:
"command": "C:\\Program Files\\nodejs\\npx.cmd"
Step 3: Restart Cursor and Test
Quit and reopen Cursor. Then test:
List the collections in my MongoDB database
Or more specifically:
Show me a sample document from the users collection
Specifying Your Database
If your MongoDB instance has multiple databases, specify which one in your prompt or in the connection string:
mongodb+srv://user:pass@cluster.mongodb.net/my_database_name
Or ask Cursor to list available databases first:
What databases are available in this MongoDB connection?
Practical Workflows
Debugging a Data Issue
I'm getting an error where some user documents don't have the
subscription_plan field. Query the users collection and find all
documents where subscription_plan is missing or null, then show
me a count and 3 example documents.
Writing a Query with Real Schema Context
I need to write a MongoDB aggregation that shows total revenue by
product category for the last 30 days. Show me what the orders
collection schema looks like first, then write the aggregation.
Cursor will inspect your actual collection structure and write the aggregation with your real field names.
Schema Discovery for a New Codebase
I just inherited this codebase. Show me sample documents from
the users, products, and orders collections so I can understand
the data model before I start writing code.
Index Analysis
The product search queries are slow. Show me the current indexes
on the products collection and what a typical search query looks like,
then recommend what indexes to add.
Multi-Database Setup
If you work with multiple MongoDB environments:
{
"mcpServers": {
"mongodb-dev": {
"command": "npx",
"args": ["-y", "@mongodb-js/mongodb-mcp-server"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/dev_db"
}
},
"mongodb-prod": {
"command": "npx",
"args": ["-y", "@mongodb-js/mongodb-mcp-server"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://user:pass@prod-cluster.mongodb.net/prod_db"
}
}
}
}
Specify in your prompt: "Using mongodb-dev, show me the users collection schema"
Available MongoDB MCP Tools
The official MongoDB MCP server exposes:
mongodb_list_databases — List all databases on the connectionmongodb_list_collections — List collections in a databasemongodb_find — Query documents with filter, projection, sort, limitmongodb_aggregate — Run aggregation pipelinesmongodb_count — Count documents matching a filtermongodb_get_indexes — List indexes on a collectionmongodb_get_schema — Infer schema from sample documentsmongodb_explain — Get query execution plan for performance analysisTroubleshooting
"MongoServerError: Authentication failed"
Your username or password in the connection string is incorrect. Test the connection string in MongoDB Compass or mongosh first to verify it works.
"MongoNetworkError: connect ECONNREFUSED"
For self-hosted: MongoDB isn't running, or the port is wrong. For Atlas: check that your IP address is in the Atlas Network Access allowlist.
"Server starts but find returns no results"
You may be querying the wrong database. Include the database name in your connection string, or ask: "What collections exist in this database?"
Atlas IP Whitelist
For Atlas clusters, add your machine's IP to the Network Access allowlist. For development, you can allow access from anywhere (0.0.0.0/0) — but don't do this in production.
---