🗄️ Mongodb Mcp 伺服器 用於 Llms
概覽
什麼是 mongo-mcp?
mongo-mcp 是一個為模型上下文協議(MCP)設計的 MongoDB 伺服器實現。這個項目的目標是提供一種穩健且高效的方式來管理和互動 MongoDB 數據庫,促進與使用 MCP 框架的應用程序的無縫集成。通過利用 MongoDB 的能力,mongo-mcp 允許開發者構建可擴展和高性能的應用程序。
mongo-mcp 的特點
- MCP 兼容性:mongo-mcp 專門設計用於與模型上下文協議一起工作,確保滿足基於此協議構建的應用程序的要求。
- 可擴展性:基於 MongoDB,mongo-mcp 可以處理大量數據和眾多並發連接,適合企業級應用程序。
- 易於使用:該伺服器設計時考慮了用戶友好性,提供簡單的安裝和配置過程。
- 開源:作為一個公共存儲庫,mongo-mcp 開放給貢獻,允許開發者合作並增強該項目。
- 活躍社區:該項目吸引了越來越多的開發者的關注和貢獻,確保持續改進和支持。
如何使用 mongo-mcp
- 安裝:首先從 GitHub 克隆存儲庫:
git clone https://github.com/QuantGeekDev/mongo-mcp.git
- 配置:導航到項目目錄,根據您的需求配置伺服器設置。這可能包括設置數據庫連接和定義協議。
- 運行伺服器:使用提供的腳本或命令啟動 mongo-mcp 伺服器。確保 MongoDB 已安裝並在您的機器上運行。
- 集成:使用 MCP 框架將您的應用程序連接到 mongo-mcp 伺服器,實現高效的數據管理和檢索。
常見問題解答
什麼是模型上下文協議(MCP)?
模型上下文協議(MCP)是一個框架,定義了應用程序如何以結構化的方式與數據模型互動。它提供了數據操作的指導方針,確保不同應用程序之間的一致性和可靠性。
mongo-mcp 適合生產使用嗎?
是的,mongo-mcp 設計為穩健且可擴展,適合生產環境。然而,建議在將其部署到實際環境之前,充分測試伺服器以符合您的特定使用情況。
我該如何為 mongo-mcp 項目做出貢獻?
歡迎貢獻!您可以通過報告問題、提交拉取請求或改善文檔來貢獻。請參考項目的 GitHub 頁面以獲取貢獻指南。
我可以在哪裡找到有關 mongo-mcp 的更多信息?
有關更詳細的信息、文檔和更新,請訪問 mongo-mcp GitHub 存儲庫。
詳細
🗄️ 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.
✨ Features
- 🔍 Collection schema inspection
- 📊 Document querying and filtering
- 📈 Index management
- 📝 Document operations (insert, update, delete)
Demo Video
https://github.com/user-attachments/assets/2389bf23-a10d-49f9-bca9-2b39a1ebe654
🚀 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
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"mongo-mcp",
"mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
]
}
}
}
Installing via Smithery
To install MongoDB MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install mongo-mcp --client claude
Prerequisites
- Node.js 18+
- npx
- Docker and Docker Compose (for local sandbox testing only)
- MCP Client (Claude Desktop App for example)
Test Sandbox Setup
If you don't have a mongo db server to connect to and want to create a sample sandbox, follow these steps
- Start MongoDB using Docker Compose:
docker-compose up -d
- Seed the database with test data:
npm run seed
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:
{
"mcpServers": {
"mongodb": {
"command": "node",
"args": [
"dist/index.js",
"mongodb://root:example@localhost:27017/test?authSource=admin"
]
}
}
}
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
"What collections are available in the database?"
"Show me the schema for the users collection"
"Find all users in San Francisco"
Advanced Queries
"Find all electronics products that are in stock and cost less than $1000"
"Show me all orders from the user john@example.com"
"List the products with ratings above 4.5"
Index Management
"What indexes exist on the users collection?"
"Create an index on the products collection for the 'category' field"
"List all indexes across all collections"
Document Operations
"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"
📝 Available Tools
The server provides these tools for database interaction:
Query Tools
find
: Query documents with filtering and projectionlistCollections
: List available collectionsinsertOne
: Insert a single documentupdateOne
: Update a single documentdeleteOne
: Delete a single document
Index Tools
createIndex
: Create a new indexdropIndex
: Remove an indexindexes
: List indexes for a collection
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
伺服器配置
{
"mcpServers": {
"mongo-mcp": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--quantgeekdev--mongo-mcp--mongo-mcp",
"node dist/index.js {{MONGODB_URI}}"
],
"env": {}
}
}
}