MongoDB MCP连接器
一个MCP服务器,它使大型语言模型能够直接与MongoDB数据库交互,从而通过自然语言查询集合、检查模式和管理数据。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"mongodb": {
"args": [
"dist/index.js",
"mongodb://root:example@localhost:27017/test?authSource=admin"
],
"command": "node"
}
}
}
该服务需要配置环境变量:MONGODB_URI
服务介绍
🗄️ 适用于LLM的MongoDB MCP服务器
这是一个模型上下文协议(MCP)服务器,它使LLM能够直接与MongoDB数据库进行交互。通过自然语言无缝查询集合、检查模式和管理数据。
✨ 特性
- 🔍 集合模式检查
- 📊 文档查询和过滤
- 📈 索引管理
- 📝 文档操作(插入、更新、删除)
演示视频
https://github.com/user-attachments/assets/2389bf23-a10d-49f9-bca9-2b39a1ebe654
🚀 快速开始
要开始使用,请找到您的mongodb连接URL并将此配置添加到您的Claude Desktop配置文件中:
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安装
要通过Smithery自动为Claude Desktop安装MongoDB MCP Server:
npx -y @smithery/cli install mongo-mcp --client claude
前提条件
- Node.js 18+
- npx
- Docker 和 Docker Compose(仅用于本地沙箱测试)
- MCP 客户端(例如 Claude Desktop 应用程序)
测试沙箱设置
如果您没有可以连接的mongo db服务器,并希望创建一个样本沙箱,请按照以下步骤操作
- 使用Docker Compose启动MongoDB:
docker-compose up -d
- 用测试数据填充数据库:
npm run seed
配置Claude Desktop
将此配置添加到您的Claude Desktop配置文件中:
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"
]
}
}
}
测试沙箱数据结构
种子脚本创建了三个带有样本数据的集合:
用户
- 个人信息(姓名、电子邮件、年龄)
- 包含坐标的嵌套地址
- 兴趣数组
- 会员日期
产品
- 产品详情(名称、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: 列出集合的索引
📜 许可证
此项目根据 MIT 许可证进行许可 - 详情请参阅 LICENSE 文件。