mcp-mongodb
mcp-mongodb
用于将 Claude 连接到 MongoDB 的 MCP(Model Context Protocol)服务器。 通过此服务器,Claude 可以直接通过对话浏览、查询和修改您的 MongoDB 数据库。
功能 / 工具
类别 | 工具 | 描述 |
信息 |
| 检查 MongoDB 连接与版本 |
| 列出所有数据库及大小 | |
数据库 |
| 数据库统计信息 |
| ⚠️ 删除数据库(必须 | |
集合 |
| 列出数据库中的集合 |
| 集合统计信息(文档数量、大小) | |
| 创建新集合 | |
| 重命名集合 | |
| ⚠️ 删除集合及其全部内容 | |
读取数据 |
| 查询文档(过滤、投影、排序、limit、skip) |
| 获取单个文档 | |
| 根据 | |
| 统计匹配的文档数量 | |
| 某个字段的唯一值 | |
| 运行聚合管道( | |
写入数据 |
| 插入文档 |
| 使用操作符更新( | |
| 替换单个文档的全部内容 | |
| ⚠️ 删除文档(空过滤器必须 | |
索引 |
| 管理索引 |
Related MCP server: Mongo-MCP
系统要求
Node.js ≥ 18(在 v22 上开发并测试)
MongoDB 服务器(本地或 MongoDB Atlas)
安装
cd d:\mcp_server\mcp_mongodb
npm install环境变量配置
变量 | 必填? | 默认值 | 说明 |
| 否 |
| MongoDB 连接 URI |
| 否 | — | 默认数据库名称;如果为空,每个工具都需要 |
Atlas URI 示例:
mongodb+srv://user:password@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority连接到 Claude Desktop
打开配置文件:
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
添加以下条目(请调整路径和凭据):
{
"mcpServers": {
"mongodb": {
"command": "node",
"args": ["d:\\mcp_server\\mcp_mongodb\\index.js"],
"env": {
"MONGODB_URI": "mongodb://localhost:27017",
"MONGODB_DB": "nama_database_anda"
}
}
}
}保存文件,然后重启 Claude Desktop(完全退出后重新打开)。
聊天框中的锤子/工具栏图标将显示
mcp-mongodb工具。
在 Claude 中的使用示例
"显示所有 MongoDB 数据库" →
list_databases"数据库 toko 中有哪些集合?" →
list_collections"查找销量最高的 10 个产品,按销量从高到低排序" → 使用
sort+limit的find"添加一个名为 'Kopi Arabika'、价格 85000 的新产品" →
insert_one"将 'minuman' 类别所有产品的库存增加 10" →
update_many"每月总销售额是多少?" → 使用
$group的aggregate"在 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 中 | 确保 |
| MongoDB 未运行 / URI 错误 / IP 未加入白名单(Atlas) |
| 检查 URI 中的用户名/密码及 |
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 stdioMaintenance
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
- AlicenseNot gradedqualityFmaintenanceEnables Claude to interact with MongoDB databases through natural language, supporting queries, aggregations, CRUD operations, and index management with optional Mongoose schema validation.503MIT
- AlicenseNot gradedqualityDmaintenanceEnables 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.3MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables Claude to interact with MongoDB databases, supporting CRUD operations, aggregation, and database management.83,587MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with MongoDB databases through natural language, supporting document CRUD, aggregation, collection listing, and statistics.83,587Apache 2.0
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
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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