The MongoDB MCP Server provides a natural language interface for LLMs to interact with MongoDB databases. This server implements the Model Context Protocol (MCP), enabling AI assistants like Claude to query collections, inspect schemas, and manage data through conversation.
Before installation, ensure you have:
Verify your Node.js installation:
node --version # Should show v18.0.0 or higher
Add this configuration to your Claude Desktop config file:
MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"mongo-mcp",
"mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
]
}
}
}
For automatic installation with Claude Desktop:
npx -y @smithery/cli install mongo-mcp --client claude
mongodb
npx
mongo-mcp mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin
Note: Cursor currently supports MCP tools only in the Agent in Composer feature.
If you don't have a MongoDB server available, you can create a test sandbox:
docker-compose up -d
npm run seed
MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mongodb": {
"command": "node",
"args": [
"dist/index.js",
"mongodb://root:example@localhost:27017/test?authSource=admin"
]
}
}
}
Try these prompts with Claude to interact with your MongoDB database:
"What collections are available in the database?"
"Show me the schema for the users collection"
"Find all users in San Francisco"
"Find all electronics products that are in stock and cost less than $1000"
"Show me all orders from the user [email protected]"
"List the products with ratings above 4.5"
"What indexes exist on the users collection?"
"Create an index on the products collection for the 'category' field"
"List all indexes across all collections"
"Insert a new product with name 'Gaming Laptop' in the products collection"
"Update the status of order with ID X to 'shipped'"
"Find and delete all products that are out of stock"
The MCP server provides these MongoDB interaction tools:
listCollections
: Lists available collections in the databasefind
: Queries documents with filtering and projectioninsertOne
: Inserts a single document into a collectionupdateOne
: Updates a single document in a collectiondeleteOne
: Deletes a single document from a collectioncreateIndex
: Creates a new index on a collectiondropIndex
: Removes an index from a collectionindexes
: Lists indexes for a collectionConnection Errors
Authentication Issues
authSource=admin
)Tool Execution Problems
# macOS
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
Performance Issues
When using this MCP server with MongoDB:
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.