mongo mcp
A protocol server that enables LLMs like Claude to interact with MongoDB databases, providing tools for schema exploration, aggregation queries, and data analysis through natural language in Cursor.
A protocol server that enables LLMs like Claude to interact with MongoDB databases, providing tools for schema exploration, aggregation queries, and data analysis through natural language in Cursor.
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.
The Model Context Protocol (MCP) is an open standard developed by Anthropic that creates a universal way for AI systems to connect with external data sources and tools. MCP establishes a standardized communication channel between:
Key benefits of MCP: - Universal Access: Provides a single protocol for AI assistants to query data from various sources - Standardized Connections: Handles authentication, usage policies, and data formats consistently - Sustainable Ecosystem: Promotes reusable connectors that work across multiple LLM clients
Before you begin, ensure you have:
You can verify your Node.js installation by running:
node --version # Should show v18.0.0 or higher
To get started, find your MongoDB connection URL and 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"
]
}
}
}
Smithery.ai is a registry platform for MCP servers that simplifies discovery and installation. To install MongoDB MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mongo-mcp --client claude
To use MongoDB MCP with Cursor.ai:
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 do not have a MongoDB server to connect to and want to create a sample sandbox, follow these steps:
docker-compose up -d
npm run seed
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": "node",
"args": [
"dist/index.js",
"mongodb://root:example@localhost:27017/test?authSource=admin"
]
}
}
}
The seed script creates three collections with sample data:
Try these prompts with Claude to explore the functionality:
"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 these tools for database interaction:
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 collectionThis project is built with:
To set up the development environment:
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev
# Run tests
npm test
When using this MCP server with your MongoDB database:
readPreference=secondary
)⚠️ IMPORTANT: Always follow the principle of least privilege when configuring database access.
The MongoDB MCP server:
All operations are executed with proper validation to prevent security issues such as injection attacks.
You can deploy this MCP server in several ways:
npm install -g @coderay/mongo-mcp-server
Ensure network permissions allow the connection
Authentication Issues
authSource=admin
)Check if MongoDB requires TLS/SSL connections
Tool Execution Problems
Check the logs for detailed error messages:
# macOS
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
Performance Issues
If you encounter issues: - Review the MCP Documentation - Submit an issue on our GitHub repository
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.