npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

multiple-mongodb-mcp

v1.0.0

Published

An MCP stdio server that provides read-only access to multiple MongoDB instances via a single MCP connection.

Readme

Multiple MongoDB MCP Server

一个 MCP (Model Context Protocol) stdio 服务器,通过单个 MCP 连接提供对多个 MongoDB 实例的访问。

特性

  • 单进程管理多个 MongoDB 实例连接
  • 默认只读模式,通过环境变量开启写操作
  • 支持 MongoDB 3.6+(使用 mongodb driver v4.x)
  • 实例健康检查(不依赖 admin 权限)
  • 每实例可配置查询文档数上限
  • 网络断开后自动重连(driver 内置机制)

项目结构

src/
├── index.ts              # 入口:MCP server 启动、请求路由、参数校验
├── types.ts              # 类型定义(MongoDBInstanceConfig, ToolResult)
├── config.ts             # 配置加载与校验(从 JSON 文件)
├── instance.ts           # MongoDBInstance 类 — 单实例连接生命周期
├── instanceManager.ts    # InstanceManager 类 — 多实例管理
└── tools/
    ├── definitions.ts    # 所有 tool 的 JSON Schema 定义(读/写分离)
    ├── read.ts           # 查询类 tool(find / aggregate / count / explain)
    ├── metadata.ts       # 元数据类 tool(databases / collections / indexes / schema / stats / logs)
    └── write.ts          # 写操作 tool(insert / update / delete / collection管理 / index管理)

配置

实例配置文件

创建一个 JSON 文件配置你的 MongoDB 实例:

{
  "instances": [
    {
      "name": "prod-mongodb",
      "description": "生产环境 MongoDB",
      "connectionString": "mongodb://user:password@host:27017/dbname?authSource=admin"
    },
    {
      "name": "stage-mongodb",
      "description": "Stage环境 MongoDB",
      "connectionString": "mongodb://user:password@stage-host:27017/?authSource=admin",
      "maxDocumentsPerQuery": 200
    }
  ]
}

配置字段

| 字段 | 必填 | 默认值 | 说明 | |------|:----:|--------|------| | name | ✅ | - | 实例唯一标识,调用 tool 时通过此名称指定实例 | | description | ❌ | "" | 实例描述,list_instances 时展示 | | connectionString | ✅ | - | MongoDB 连接字符串(mongodb:// 或 mongodb+srv://) | | connectTimeoutMS | ❌ | 10000 | 连接超时时间(ms) | | serverSelectionTimeoutMS | ❌ | 10000 | 服务器选择超时时间(ms) | | maxDocumentsPerQuery | ❌ | 100 | 每次查询返回的最大文档数 |

环境变量

| 变量 | 必填 | 说明 | |------|:----:|------| | MONGODB_CONFIG_FILE | ✅ | 实例配置 JSON 文件路径 | | MONGODB_WRITABLE | ❌ | 设为 true 开启写操作,默认只读 |

Kiro MCP Setting

在 .kiro/settings/mcp.json 或 ~/.kiro/settings/mcp.json 中添加:

{
  "mcpServers": {
    "multiple-mongodb": {
      "command": "node",
      "args": ["/path/to/multiple-mongodb-mcp/build/index.js"],
      "env": {
        "MONGODB_CONFIG_FILE": "/path/to/mongodb-instances.json",
        "MONGODB_WRITABLE": "false"
      }
    }
  }
}

可用 Tools

读操作(始终可用,共 13 个)

| Tool | 说明 | |------|------| | list_instances | 列出所有配置的实例及可用状态 | | list_databases | 列出指定实例的所有数据库 | | list_collections | 列出数据库中的所有集合 | | find | 执行 find 查询 | | aggregate | 执行集合级聚合管道 | | aggregate_db | 执行数据库级聚合管道 | | count | 文档计数(支持 filter) | | explain | 获取查询执行计划 | | collection_indexes | 列出集合索引 | | collection_schema | 采样推断集合 schema | | collection_storage_size | 获取集合存储大小 | | db_stats | 获取数据库统计信息 | | mongodb_logs | 获取 mongod 日志 |

写操作(需要 MONGODB_WRITABLE=true,共 9 个)

| Tool | 说明 | |------|------| | insert_many | 批量插入文档 | | update_many | 批量更新文档 | | delete_many | 批量删除文档 | | create_collection | 创建集合 | | drop_collection | 删除集合 | | drop_database | 删除数据库 | | rename_collection | 重命名集合 | | create_index | 创建索引 | | drop_index | 删除索引 |

构建

npm install
npm run build

开发

npm run watch

使用 MCP Inspector 测试

MONGODB_CONFIG_FILE=./mongodb-instances.json npx @modelcontextprotocol/inspector node build/index.js