Enables LLMs to interact directly with MongoDB databases, allowing querying collections, inspecting schemas, and managing data through natural language interfaces.
🗄️ MongoDB MCP Server for LLMS
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 Model Context Protocol (MCP)?
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:
MCP Clients: AI assistants like Claude that consume data (e.g., Claude Desktop, Cursor.ai)
MCP Servers: Services that expose data and functionality (like this MongoDB server)
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
✨ Features
🔍 Collection schema inspection
📊 Document querying and filtering
📈 Index management
📝 Document operations (insert, update, delete)
🔒 Secure database access through connection strings
📋 Comprehensive error handling and validation
📋 Prerequisites
Before you begin, ensure you have:
Node.js (v18 or higher)
MongoDB instance (local or remote)
An MCP client like Claude Desktop or Cursor.ai
You can verify your Node.js installation by running:
🚀 Quick Start
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
Installing via Smithery
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:
Cursor.ai Integration
To use MongoDB MCP with Cursor.ai:
Open Cursor.ai and navigate to Settings > Features
Look for "MCP Servers" in the features panel
Add a new MCP server with the following configuration:
Name:
mongodb
Command:
npx
Args:
mongo-mcp mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin
Note: Cursor currently supports MCP tools only in the Agent in Composer feature.
Test Sandbox Setup
If you don't have a MongoDB server to connect to and want to create a sample sandbox, follow these steps:
Start MongoDB using Docker Compose:
Seed the database with test data:
Configure Claude Desktop
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
Local Development Mode:
Test Sandbox Data Structure
The seed script creates three collections with sample data:
Users
Personal info (name, email, age)
Nested address with coordinates
Arrays of interests
Membership dates
Products
Product details (name, SKU, category)
Nested specifications
Price and inventory info
Tags and ratings
Orders
Order details with items
User references
Shipping and payment info
Status tracking
🎯 Example Prompts
Try these prompts with Claude to explore the functionality:
Basic Operations
Advanced Queries
Index Management
Document Operations
📝 Available Tools
The server provides these tools for database interaction:
Query 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 collection
Index Tools
createIndex
: Creates a new index on a collectiondropIndex
: Removes an index from a collectionindexes
: Lists indexes for a collection
🛠️ Development
This project is built with:
TypeScript for type-safe development
MongoDB Node.js driver for database operations
Zod for schema validation
Model Context Protocol SDK for server implementation
To set up the development environment:
🔒 Security Considerations
When using this MCP server with your MongoDB database:
Create a dedicated MongoDB user with minimal permissions needed for your use case
Never use admin credentials in production environments
Enable access logging for audit purposes
Set appropriate read/write permissions on collections
Use connection string parameters to restrict access (e.g.,
readPreference=secondary
)Consider IP allow-listing to restrict database access
⚠️ IMPORTANT: Always follow the principle of least privilege when configuring database access.
🌐 How It Works
The MongoDB MCP server:
Connects to your MongoDB database using the connection string provided
Exposes MongoDB operations as tools that follow the MCP specification
Validates inputs using Zod for type safety and security
Executes queries and returns structured data to the LLM client
Manages connection pooling and proper error handling
All operations are executed with proper validation to prevent security issues such as injection attacks.
📦 Deployment
You can deploy this MCP server in several ways:
Locally via npx (as shown in Quick Start)
As a global npm package:
npm install -g @coderay/mongo-mcp-server
In a Docker container (see Dockerfile in the repository)
As a service on platforms like Heroku, Vercel, or AWS
❓ Troubleshooting
Common Issues
Connection Errors
Verify your MongoDB connection string is correct
Check that your MongoDB server is running and accessible
Ensure network permissions allow the connection
Authentication Issues
Confirm username and password are correct
Verify the authentication database is specified (usually
authSource=admin
)Check if MongoDB requires TLS/SSL connections
Tool Execution Problems
Restart Claude Desktop or Cursor.ai completely
Check the logs for detailed error messages:
# macOS tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
Performance Issues
Consider adding appropriate indexes to frequently queried fields
Use projection to limit the data returned in queries
Use limit and skip parameters for pagination
Getting Help
If you encounter issues:
Review the MCP Documentation
Submit an issue on our GitHub repository
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Fork the repository
Create your feature branch (
git checkout -b feature/amazing-feature
)Commit your changes (
git commit -m 'Add some amazing feature'
)Push to the branch (
git push origin feature/amazing-feature
)Open a Pull Request
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
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.
- 📚 What is Model Context Protocol (MCP)?
- ✨ Features
- 📋 Prerequisites
- 🚀 Quick Start
- 🎯 Example Prompts
- 📝 Available Tools
- 🛠️ Development
- 🔒 Security Considerations
- 🌐 How It Works
- 📦 Deployment
- ❓ Troubleshooting
- 🤝 Contributing
- 📜 License
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server that provides access to MongoDB databases. This server enables LLMs to inspect collection schemas and execute read-only queries.Last updated -8292264MIT License
- -securityAlicense-qualityA Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.Last updated -1091MIT License
- -securityAlicense-qualityA Model Context Protocol server that enables LLMs to interact directly with MongoDB databases, allowing users to query collections, inspect schemas, and manage data through natural language.Last updated -109MIT License
- -securityAlicense-qualityA Model Context Protocol (MCP) server that enables LLMs to interact directly with MongoDB databases, allowing them to query collections, inspect schemas, and manage data seamlessly through natural language.