MongoDB MCP Server

by linpeibiao

Not rated
GitHub

About

A server for performing CRUD operations on a MongoDB database.

Details

Author
linpeibiao
Categories
Database, Other

Setup

Install MongoDB MCP Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/linpeibiao/mongodb-mcp-server

Follow the installation instructions in the repository README, then restart your MCP client.

基于 FastMCP 和 uv 工具的 MongoDB MCP(Model Context Protocol)服务器,提供完整的 CRUD 操作功能。

- ✅连接管理: 连接和断开 MongoDB 数据库
- ✅创建文档: 向集合中插入新文档
- ✅读取文档: 从集合中查询文档,支持过滤、分页
- ✅更新文档: 更新集合中的文档,支持 upsert
- ✅删除文档: 从集合中删除文档
- ✅错误处理: 完善的错误处理和日志记录
- ✅数据序列化: 自动处理 ObjectId 等 MongoDB 特殊类型

# 安装 uv(如果还没安装) curl -LsSf https://astral.sh/uv/install.sh | sh # 安装项目依赖 uv pip install -e .

- connection_string(str): MongoDB 连接字符串
- database_name(str): 数据库名称

{ "connection_string": "mongodb://localhost:27017", "database_name": "myapp" }

- collection_name(str): 集合名称
- document(dict): 要插入的文档内容

{ "collection_name": "users", "document": { "name": "张三", "age": 25, "email": "zhangsan@example.com" } }

- collection_name(str): 集合名称
- filter(dict, 可选): 查询过滤条件
- limit(int, 可选): 限制返回数量
- skip(int, 可选): 跳过的文档数量

{ "collection_name": "users", "filter": {"age": {"$gte": 18}}, "limit": 10, "skip": 0 }

- collection_name(str): 集合名称
- filter(dict): 更新条件
- update(dict): 更新操作
- upsert(bool, 可选): 如果文档不存在是否创建,默认为 false

{ "collection_name": "users", "filter": {"name": "张三"}, "update": {"$set": {"age": 26}}, "upsert": false }

- collection_name(str): 集合名称
- filter(dict): 删除条件

{ "collection_name": "users", "filter": {"age": {"$lt": 18}} }
# 直接运行 python -m my_mongo_mcp.server # 或者使用安装的脚本 my-mongo-mcp
{ "mcpServers": { "mongodb": { "command": "python", "args": ["-m", "my_mongo_mcp.server"], "env": {} } } }
工具: connect 参数: {"connection_string": "mongodb://localhost:27017", "database_name": "testdb"}
工具: create 参数: { "collection_name": "users", "document": {"name": "李四", "age": 30, "city": "上海"} }
工具: read 参数: { "collection_name": "users", "filter": {"city": "上海"}, "limit": 5 }
工具: update 参数: { "collection_name": "users", "filter": {"name": "李四"}, "update": {"$set": {"age": 31}} }
工具: delete 参数: { "collection_name": "users", "filter": {"name": "李四"} }

- 使用前请确保 MongoDB 服务器正在运行
- 所有操作都需要先连接数据库
- ObjectId 等特殊类型会自动转换为字符串
- 支持所有标准的 MongoDB 查询语法
- 错误信息会以中文形式返回

- Python 3.8+
- MongoDB 3.6+
- fastmcp 0.2.0+
- pymongo 4.6.0+

- 检查 MongoDB 服务是否启动
- 验证连接字符串是否正确
- 检查网络连接和防火墙设置

- 确保 JSON 数据格式正确
- 注意 ObjectId 的格式要求 "# mongodb-mcp-server"

Interact with MongoDB databases using natural language to query collections, inspect schemas, and manage data.

Interact with MongoDB databases using natural language. Query collections, inspect schemas, and manage data.

Provides read-only access to MongoDB databases through standardized MCP tools and resources.

An MCP server providing tools and prompts for interacting with a MongoDB database.

A server for querying and analyzing the MongoDB sample_mflix movie database.

A MongoDB MCP server with schema discovery and field validation. Requires a MONGODB_URI environment variable.

Official MCP server for dbt (data build tool) providing integration with dbt Core/Cloud CLI, project metadata discovery, model information, and semantic layer querying capabilities.

Provides AI assistants with a secure and structured way to explore and analyze data in GreptimeDB.

Build robust data workflows, integrations, and analytics on a single intuitive platform.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.