关于 🗄️ MongoDB MCP Server for LLMS
MongoDB MCP Server for LLMS 是让 LLM 直接访问 MongoDB 数据库的 MCP 服务。可通过自然语言查询集合、查看结构并管理数据,适合需要用 AI 操作 MongoDB 的开发者。
主要功能
- 01集合结构检查
- 02文档查询与过滤
- 03索引管理
- 04文档的插入、更新与删除
适用场景
- 01让 AI 查看集合结构并编写查询
- 02在本地沙箱环境中试用 MongoDB 操作
- 03为集合创建或删除索引
MCP 相关
该项目是 MCP 服务,向 MCP 客户端提供 find、listCollections、insertOne、updateOne、deleteOne、createIndex、dropIndex、indexes 等工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
🗄️ 面向大模型的 MongoDB MCP 服务
一个模型上下文协议(MCP)服务,可让大模型直接与 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 服务:
npx -y @smithery/cli install mongo-mcp --client claude
前置条件
- Node.js 18+
- npx
- Docker 和 Docker Compose(仅用于本地沙盒测试)
- MCP 客户端(例如 Claude Desktop App)
设置测试沙盒
如果你没有可连接的 MongoDB 服务,并且想创建一个示例沙盒,请按照以下步骤操作
- 使用 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 [email protected]"
"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 文件。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。