🗄️ 用于LLMS的MongoDB MCP服务器
](https://nodejs.org/en/)  ](https://smithery.ai/server/mongo-mcp)
一种模型上下文协议(MCP)服务器,使LLM能够直接与MongoDB数据库交互。通过自然语言无缝查询集合、检查模式和管理数据。
✨ 特性
- 🔍 收集模式检查
- 📊 文档查询和过滤
- 📈 指标管理
- 📝 文档操作(插入、更新、删除)
🚀 快速开始
要开始使用,请找到您的mongodb连接url,并将此配置添加到您的Claude Desktop配置文件中:
MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json\ 视窗: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"mongo-mcp",
"mongodb://:
@:
/?authSource=admin"
]
}
}
}先决条件
- Node.js 18+
- 新巴拿马型船舶
- Docker和Docker Compose(仅用于本地沙盒测试)
- MCP客户端(例如克劳德桌面应用程序)
测试沙盒设置
如果您没有mongo-db服务器可以连接,并且想创建一个示例沙盒,请按照以下步骤操作
- 使用Docker Compose启动MongoDB:
docker-compose up -d- 为数据库添加测试数据种子:
npm run seed配置Claude桌面
将此配置添加到您的Claude Desktop配置文件中:
MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json\ 视窗: %APPDATA%/Claude/claude_desktop_config.json
地方发展模式:
{
"mcpServers": {
"mongodb": {
"command": "node",
"args": [
"dist/index.js",
"mongodb://root:example@localhost:27017/test?authSource=admin"
]
}
}
}测试沙盒数据结构
种子脚本使用示例数据创建了三个集合:
用户
- 个人信息(姓名、电子邮件、年龄)
- 带坐标的嵌套地址
- 兴趣爱好
- 会员日期
产品
- 产品详细信息(名称、SKU、类别)
- 嵌套规范
- 价格和库存信息
- 标签和评级
订单
- 包含商品的订单详细信息
- 用户参考
- 发货和付款信息
- 状态跟踪
🎯 示例提示
与Claude一起尝试以下提示以探索功能:
基本操作
"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 john@example.com"
"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"📝 可用工具
服务器为数据库交互提供了以下工具:
查询工具
find:通过过滤和投影查询文档listCollections:列出可用收藏insertOne:插入单个文档updateOne:更新单个文档deleteOne:删除单个文档
索引工具
createIndex:创建新索引dropIndex:删除索引indexes:列出集合的索引
认证机构:-
MCP Reviews: https://mcpreview.com/mcp-servers/nickiiitu/MongoDB-Model-Context-Protocol-MCP-
📜 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
