M

MongoDB模型上下文协议服务

@nickiiitu/MongoDB-Model-Context-Protocol-MCP-
0 Stars 394 次浏览 nickiiitu 更新于 2026-08-23

一种模型上下文协议服务器,使大型语言模型能够直接与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服务器



smithery badge

这是一个模型上下文协议(MCP)服务器,它使大型语言模型(LLMs)能够直接与MongoDB数据库进行交互。通过自然语言无缝查询集合、检查模式和管理数据。

✨ 特性

  • 🔍 集合模式检查
  • 📊 文档查询和过滤
  • 📈 索引管理
  • 📝 文档操作(插入、更新、删除)

演示视频

https://github.com/user-attachments/assets/2389bf23-a10d-49f9-bca9-2b39a1ebe654

🚀 快速开始

要开始使用,请找到您的MongoDB连接URL并将此配置添加到您的Claude桌面配置文件中:

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 桌面应用程序)

测试沙盒设置

如果您没有MongoDB服务器可连接,并且想要创建一个示例沙盒,请按照以下步骤操作:

  1. 使用Docker Compose启动MongoDB:
docker-compose up -d
  1. 使用测试数据填充数据库:
npm run seed

配置Claude桌面应用

将此配置添加到您的Claude桌面配置文件中:

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 文件。

MongoDB-Model-Context-Protocol-MCP-

相关 MCP 服务