This MCP server allows Large Language Models like Claude to interact directly with MongoDB databases through natural language. You can query collections, inspect schemas, and manage data without writing MongoDB code directly.
To use the MongoDB MCP Server with Claude Desktop, you need to add configuration to your Claude Desktop config file.
Add this to your Claude Desktop configuration file:
MacOS:
~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%/Claude/claude_desktop_config.json
Add the following JSON:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"mongo-mcp",
"mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
]
}
}
}
Replace <username>
, <password>
, <host>
, <port>
, and <database>
with your MongoDB connection details.
For automatic installation with Claude Desktop:
npx -y @smithery/cli install mongo-mcp --client claude
If you don't have a MongoDB server to connect to, you can create a sample sandbox:
docker-compose up -d
npm run seed
{
"mcpServers": {
"mongodb": {
"command": "node",
"args": [
"dist/index.js",
"mongodb://root:example@localhost:27017/test?authSource=admin"
]
}
}
}
Once configured, you can use natural language to interact with your MongoDB database through Claude. Here are example prompts to try:
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 server provides the following tools for database interaction:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mongodb" '{"command":"npx","args":["mongo-mcp","mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"]}'
See the official Claude Code MCP documentation for more details.
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 > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"mongo-mcp",
"mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
]
}
}
}
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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"mongo-mcp",
"mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect