MongoDB MCP
A MongoDB MCP Server that allows AI agents and MCP clients to interact with MongoDB databases through standardized tools for CRUD operations, schema discovery, and collection management.
README
MongoDB MCP
A MongoDB Model Context Protocol (MCP) Server that allows AI agents and MCP clients to interact with MongoDB databases through standardized tools.
Features
- List all collections
- Discover collection schemas
- Fetch collection data
- Query documents
- Insert documents
- Update documents
- Delete documents
- MongoDB Atlas support
- Local MongoDB support
- MCP stdio transport support
Installation
Using pip
pip install mongo-mcp
Using uv
uv add mongo-mcp
Prerequisites
- Python 3.10+
- MongoDB Local Instance or MongoDB Atlas Cluster
Examples:
mongodb://localhost:27017
or
mongodb+srv://username:password@cluster.mongodb.net
Configuration
MongoDB MCP uses environment variables to connect to your database.
Create a .env file:
MONGODB_URI=mongodb://localhost:27017
DATABASE_NAME=shipbihar
Environment Variables
| Variable | Description | Required |
|---|---|---|
| MONGODB_URI | MongoDB connection string | Yes |
| DATABASE_NAME | Database name | Yes |
Running the MCP Server
mongo_mcp
or
python -m mongo_mcp.main
The MCP server will start using stdio transport.
MCP Client Configuration
Example MCP configuration:
{
"mcpServers": {
"mongodb": {
"command": "mongo_mcp",
"env": {
"MONGODB_URI": "mongodb://localhost:27017",
"DATABASE_NAME": "shipbihar"
}
}
}
}
Available Tools
all_collections
Returns all collections in the configured database.
Example Output:
[
"users",
"orders",
"shipments"
]
fetch_collection_schema
Returns an inferred schema from a sample document.
Example:
{
"_id": "ObjectId",
"name": "str",
"email": "str",
"createdAt": "datetime"
}
fetch_collection_data
Returns documents from a collection.
Parameters:
{
"collection_name": "users",
"limit": 100
}
find_document
Find a document using a MongoDB query.
Example:
{
"collection_name": "users",
"query": {
"email": "john@example.com"
}
}
insert_document
Insert a document.
Example:
{
"collection_name": "users",
"document": {
"name": "John",
"email": "john@example.com"
}
}
update_document
Update matching documents.
Example:
{
"collection_name": "users",
"filter_query": {
"email": "john@example.com"
},
"update_data": {
"role": "admin"
}
}
delete_document
Delete matching documents.
Example:
{
"collection_name": "users",
"filter_query": {
"email": "john@example.com"
}
}
Common Errors
Error: DATABASE_NAME is None
Error:
TypeError: name must be an instance of str, not <class 'NoneType'>
Reason:
MongoDB MCP cannot find the DATABASE_NAME environment variable.
Solution:
Create a .env file:
MONGODB_URI=mongodb://localhost:27017
DATABASE_NAME=your_database_name
or export variables manually.
Windows PowerShell:
$env:MONGODB_URI="mongodb://localhost:27017"
$env:DATABASE_NAME="shipbihar"
Linux/macOS:
export MONGODB_URI="mongodb://localhost:27017"
export DATABASE_NAME="shipbihar"
Error: Connection Refused
Error:
ServerSelectionTimeoutError
Reason:
MongoDB server is not running.
Solution:
Start MongoDB:
mongod
or verify your Atlas connection string.
Error: Authentication Failed
Error:
Authentication failed
Reason:
Incorrect username or password.
Solution:
Verify your MongoDB credentials.
Security
Recommended:
- Use dedicated database users
- Restrict permissions when possible
- Avoid connecting with admin credentials
- Store secrets in environment variables
Do NOT:
- Commit
.envfiles to GitHub - Hardcode MongoDB passwords in code
Development
Clone the repository:
git clone <repository-url>
cd mongo-mcp
Create environment:
uv venv
source .venv/bin/activate
Install dependencies:
uv sync
Run locally:
python -m mongo_mcp.main
Roadmap
V1
- Collection discovery
- CRUD operations
- Schema inspection
V2
- Aggregation pipelines
- Count documents
- Regex search
V3
- Natural language queries
- Query optimization
- Schema caching
License
MIT License
Author
Vishnu Bhardwaj
Built for AI Agents, MCP Clients, and MongoDB Developers.
mongo_agent_mcp
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。