MCP MongoDB Server

MCP MongoDB Server

用于MongoDB的模型上下文协议服务器。

简介

MCP MongoDB 服务器让大语言模型可以直接访问 MongoDB 数据库,检查集合模式并执行数据库操作。

NPM 版本 NPM 下载量 smithery 徽章

安装方式

通过 Smithery 安装(推荐)

npx -y @smithery/cli install mcp-mongo-server --client claude

通过 mcp-get 安装

npx @michaellatman/mcp-get@latest install mcp-mongo-server

手动安装(Claude 桌面版)

编辑 Claude 桌面配置文件:

  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json

添加以下配置:

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://用户名:密码@主机地址/数据库名"
      ]
    },
    "mongodb-readonly": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mongo-server",
        "mongodb://用户名:密码@主机地址/数据库名",
        "--read-only"
      ]
    }
  }
}

主要功能

  • 集合访问: 浏览数据库集合及其模式
  • 查询与聚合: 执行查询和聚合操作
  • 数据操作: 插入、更新文档
  • 索引管理: 创建索引
  • 只读模式: 使用 --read-only 安全访问生产数据库

工具使用示例

以下是在与 Claude 对话时您可以要求执行的一些操作:

请分析 users 集合的结构和内容
对 orders 集合执行查询,查找状态为 "pending" 的订单
在 products 集合中创建一个价格字段的索引

只读模式

为保护生产数据库,可使用只读模式:

mcp-mongo-server mongodb://用户名:密码@主机地址/数据库名 --read-only

开发调试

调试服务器:

npm run inspector

访问显示的 URL 以打开调试工具。


更多详细信息请访问 GitHub 仓库