Connect LLMs to MongoDB Databases
MongoDB MCP Server for LLMs: Analyze schemas, execute MongoDB operations, and manage data via a standardized interface.
Why it matters
Enable Large Language Models to interact with MongoDB databases, allowing for schema analysis and data operations through a standardized interface.
Outcomes
What it gets done
Execute MongoDB queries and aggregation pipelines
Analyze collection schemas and retrieve server information
Perform data manipulation tasks like updates and inserts
Facilitate LLM-driven data exploration and analysis
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-mongodb | bash Capabilities
Tools your agent gets
Execute MongoDB queries with optional execution plan analysis
Run aggregation pipelines with optional query planning
Count documents matching criteria
Modify documents in collections
Add new documents to collections
Create collection indexes
Retrieve MongoDB server details and debugging information
Overview
MongoDB MCP Server
What it does
As an AI developer, I want to integrate LLM capabilities with my MongoDB databases so that I can perform data analysis and manipulation tasks programmatically. This server enables AI-driven database interactions for enhanced data insights and automation. The server executes specific MongoDB operations like querying, updating, and aggregating data through a standardized MCP interface.
Installation can be done via npm:
npm install -g mcp-mongo-server
How it connects
2023-10-27T10:00:00Z
Source README
An MCP server that enables LLMs to interact with MongoDB databases, providing capabilities for analyzing collection schemas and executing MongoDB operations through a standardized interface.
Installation
NPX
npm install -g mcp-mongo-server
From Source
git clone https://github.com/kiliczsh/mcp-mongo-server.git
cd mcp-mongo-server
npm install
npm run build
Docker
docker build -t mcp-mongo-server .
docker run -it -d -e MCP_MONGODB_URI="mongodb://muhammed:kilic@localhost:27017/database" -e MCP_MONGODB_READONLY="true" mcp-mongo-server
Smithery
npx -y @smithery/cli install mcp-mongo-server --client claude
mcp-get
npx @michaellatman/mcp-get@latest install mcp-mongo-server
Configuration
Claude Desktop - Command Arguments
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database"
]
}
}
}
Claude Desktop - Environment Variables
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server"
],
"env": {
"MCP_MONGODB_URI": "mongodb://muhammed:kilic@localhost:27017/database"
}
}
}
}
Windsurf Configuration
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database"
]
}
}
}
Cursor Configuration
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mcp-mongo-server",
"mongodb://muhammed:kilic@localhost:27017/database"
]
}
}
}
Available Tools
| Tool | Description |
|---|---|
query |
Execute MongoDB queries with optional execution plan analysis |
aggregate |
Run aggregation pipelines with optional query planning |
count |
Count documents matching criteria |
update |
Modify documents in collections |
insert |
Add new documents to collections |
createIndex |
Create collection indexes |
serverInfo |
Retrieve MongoDB server details and debugging information |
Features
- Intelligent ObjectId handling with customizable conversion modes
- Read-only mode for safe production database access
- Collection schema analysis and output
- Execution plan analysis for query optimization
- Aggregation pipeline support
- Index creation and management
- Collection autocompletion for improved LLM interaction
- Flexible configuration via environment variables or command-line options
- Secondary read preference for optimal performance in read-only mode
Environment Variables
Optional
MCP_MONGODB_URI- MongoDB connection URIMCP_MONGODB_READONLY- Enables read-only mode when set to 'true'
Usage Examples
Find all users over 30 with their names and email
Count all electronic items in inventory
Get total sales by customers using aggregation
Update a post title by ID
Insert new comments into the comments collection
Notes
Supports multiple ObjectId conversion modes (auto, none, force). Use MCP Inspector for debugging with 'npm run inspector'. Includes evaluation support with the mcp-eval package. Compatible with Claude Desktop, Windsurf, and Cursor editors.
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.