Skip to main content
Glama
mongodb-developer

MongoDB MCP Server

Official

MongoDB MCP 服务器

提供对 MongoDB 数据库的只读访问的模型上下文协议 (MLM) 服务器。该服务器使 LLM 能够检查集合模式并执行聚合管道。

成分

工具

  • 总计的

    • 针对连接的数据库执行 MongoDB 聚合管道

    • 输入:

      • collection (字符串):要查询的集合

      • pipeline (数组):MongoDB 聚合管道阶段

      • options (对象):可选的聚合设置

        • allowDiskUse (布尔值):允许需要使用磁盘的操作

        • maxTimeMS (数字):最大执行时间(以毫秒为单位)

        • comment (字符串):用于标识操作的注释

    • 如果未指定限制阶段,则默认限制为 1000 个文档

    • 默认超时时间为 30 秒

  • 解释

    • 获取聚合管道的执行计划

    • 输入:

      • collection (字符串):要分析的集合

      • pipeline (数组):MongoDB 聚合管道阶段

      • verbosity (字符串):解释的详细程度

        • 选项:“queryPlanner”、“executionStats”、“allPlansExecution”

        • 默认值:“queryPlanner”

资源

服务器为数据库中的每个集合提供架构信息:

  • 集合模式( mongodb://<host>/<collection>/schema )

    • 推断每个集合的 JSON 架构信息

    • 包括字段名称和数据类型

    • 模式源自采样收集文档

Related MCP server: MongoDB MCP Server

与 Claude Desktop 一起使用

要将此服务器与 Claude Desktop 应用程序一起使用,请将以下配置添加到claude_desktop_config.json的“mcpServers”部分:

"mongodb": {
      "command": "npx",
      "args": [
        "-y" ,
        "@pash1986/mcp-server-mongodb"
      ],
     "env" : {
	"MONGODB_URI" : "mongodb+srv://<yourcluster>" // 'mongodb://localhost:27017'
	}
    }

将mydb替换为您的数据库名称,并根据需要调整连接字符串。

示例用法

基本聚合

{
  "collection": "users",
  "pipeline": [
    { "$match": { "age": { "$gt": 21 } } },
    { "$group": {
      "_id": "$city",
      "avgAge": { "$avg": "$age" },
      "count": { "$sum": 1 }
    }},
    { "$sort": { "count": -1 } },
    { "$limit": 10 }
  ],
  "options": {
    "allowDiskUse": true,
    "maxTimeMS": 60000,
    "comment": "City-wise user statistics"
  }
}

查询说明

{
  "collection": "users",
  "pipeline": [
    { "$match": { "age": { "$gt": 21 } } },
    { "$sort": { "age": 1 } }
  ],
  "verbosity": "executionStats"
}

安全功能

  • 如果管道中未指定限制,则自动限制为 1000 个文档

  • 所有操作的默认超时时间为 30 秒

  • 仅限只读操作

  • 从收集样本中推断安全模式

执照

此 MCP 服务器采用 MIT 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    C
    maintenance
    Provides read-only access to legacy MongoDB instances (<4.0) via the Model Context Protocol, enabling AI models to query databases, collections, and run aggregations safely.
    2
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to interact with MongoDB databases through natural language, supporting document CRUD, aggregation, collection listing, and statistics.
    119,218 npm
    Apache 2.0
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to interact with MongoDB databases and MongoDB Atlas, supporting read-only and write operations, Atlas cluster management, and data exploration.
    119,218 npm
    Apache 2.0
  • A
    license
    B
    quality
    D
    maintenance
    Enables AI assistants to interact with MongoDB 3.6+ databases, supporting collection listing, document queries, counting, and aggregations through natural language.
    5
    1
    MIT