Skip to main content
Glama
chzkyy

mcp-mongodb

by chzkyy

mcp-mongodb

用于将 Claude 连接到 MongoDB 的 MCP(Model Context Protocol)服务器。 通过此服务器,Claude 可以直接通过对话浏览、查询和修改您的 MongoDB 数据库。

功能 / 工具

类别

工具

描述

信息

server_info

检查 MongoDB 连接与版本

list_databases

列出所有数据库及大小

数据库

db_stats

数据库统计信息

drop_database

⚠️ 删除数据库(必须 confirm: true

集合

list_collections

列出数据库中的集合

collection_stats

集合统计信息(文档数量、大小)

create_collection

创建新集合

rename_collection

重命名集合

drop_collection

⚠️ 删除集合及其全部内容

读取数据

find

查询文档(过滤、投影、排序、limit、skip)

find_one

获取单个文档

get_by_id

根据 _id 获取文档(自动转换 ObjectId)

count

统计匹配的文档数量

distinct

某个字段的唯一值

aggregate

运行聚合管道($match$group$lookup 等)

写入数据

insert_one / insert_many

插入文档

update_one / update_many

使用操作符更新($set$inc 等)

replace_one

替换单个文档的全部内容

delete_one / delete_many

⚠️ 删除文档(空过滤器必须 confirm: true

索引

create_index / drop_index / list_indexes

管理索引

Related MCP server: Mongo-MCP

系统要求

  • Node.js ≥ 18(在 v22 上开发并测试)

  • MongoDB 服务器(本地或 MongoDB Atlas)

安装

cd d:\mcp_server\mcp_mongodb
npm install

环境变量配置

变量

必填?

默认值

说明

MONGODB_URI

mongodb://localhost:27017

MongoDB 连接 URI

MONGODB_DB

默认数据库名称;如果为空,每个工具都需要 database 参数

Atlas URI 示例:

mongodb+srv://user:password@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority

连接到 Claude Desktop

  1. 打开配置文件:

    • Windows: %APPDATA%\Claude\claude_desktop_config.json (通常是 C:\Users\<您的用户名>\AppData\Roaming\Claude\claude_desktop_config.json

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  2. 添加以下条目(请调整路径和凭据):

{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": ["d:\\mcp_server\\mcp_mongodb\\index.js"],
      "env": {
        "MONGODB_URI": "mongodb://localhost:27017",
        "MONGODB_DB": "nama_database_anda"
      }
    }
  }
}
  1. 保存文件,然后重启 Claude Desktop(完全退出后重新打开)。

  2. 聊天框中的锤子/工具栏图标将显示 mcp-mongodb 工具。

在 Claude 中的使用示例

  • "显示所有 MongoDB 数据库"list_databases

  • "数据库 toko 中有哪些集合?"list_collections

  • "查找销量最高的 10 个产品,按销量从高到低排序" → 使用 sort + limitfind

  • "添加一个名为 'Kopi Arabika'、价格 85000 的新产品"insert_one

  • "将 'minuman' 类别所有产品的库存增加 10"update_many

  • "每月总销售额是多少?" → 使用 $groupaggregate

  • "在 users 集合的 email 字段上创建唯一索引"create_index

测试

协议冒烟测试(无需 MongoDB 运行):

npm test

预期输出:

PASS: initialize — server=mcp-mongodb v1.0.0
PASS: tools/list — 25 tool terdaftar
PASS: tool inti tersedia — semua ada
PASS: tools/call merespons

冒烟测试中对 server_info 的调用在 MongoDB 未运行时将显示错误消息——这是正常现象, 反而证明了 RPC 通道正常工作。

安全与重要说明

  • 使用具有最低必要权限的 MongoDB 账户。 如果您只希望 Claude 读取数据, 请在 MongoDB/Atlas 中创建只读用户。

  • 不要将密码保存在提交到 git 的文件中。生产环境建议将 MONGODB_URI 存储在系统环境变量中, 而不是放在 config JSON 中。

  • 破坏性操作受到保护:drop_database 和带空过滤器的 delete_many 要求显式确认 (confirm: true),但带特定过滤器的 update_many / delete_many 仍会直接执行—— 在批准之前请始终检查 Claude 的操作计划。

  • 查询输出有限制(默认 50 个文档,最大 1000 个),以免超出 Claude 的上下文。

故障排查

问题

解决方案

工具未出现在 Claude 中

确保 nodeindex.js 的路径正确;在 Claude Desktop 中查看 MCP 日志(设置 ▸ 开发者)

ServerSelectionTimeoutError

MongoDB 未运行 / URI 错误 / IP 未加入白名单(Atlas)

Authentication failed

检查 URI 中的用户名/密码及 authSource

Windows 上的 \ 字符

在 JSON 配置中使用双反斜杠(\\)或正斜杠(/

项目结构

mcp_mongodb/
├── index.js           # Entry point: McpServer + StdioServerTransport
├── lib/
│   ├── connection.js  # Singleton MongoClient (lazy connect), env config
│   ├── helpers.js     # Result builder, parser JSON, util ObjectId
│   └── schemas.js     # Skema Zod bersama
├── tools/
│   ├── admin.js       # Info server, database, koleksi
│   ├── query.js       # Pembacaan data & agregasi
│   ├── documents.js   # Insert/update/replace/delete
│   └── indexes.js     # Manajemen index
└── test-smoke.js      # Smoke test JSON-RPC via stdio
Install Server
F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    F
    maintenance
    Enables Claude to interact with MongoDB databases through natural language, supporting queries, aggregations, CRUD operations, and index management with optional Mongoose schema validation.
    50
    3
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables LLMs to interact with MongoDB databases through a complete suite of CRUD operations, administrative tasks, and index management tools. It supports database and collection handling, aggregation pipelines, and comprehensive server monitoring via the Model Context Protocol.
    3
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that enables Claude to interact with MongoDB databases, supporting CRUD operations, aggregation, and database management.
    83,587
    MIT
  • 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.
    83,587
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • MCP server giving Claude AI access to 22+ NYC public-record databases for real estate due diligence

  • Connect Claude to Fathom meeting recordings, transcripts, and summaries

  • GibsonAI MCP server: manage your databases with natural language

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chzkyy/mcp_mongodb'

If you have feedback or need assistance with the MCP directory API, please join our Discord server