MongoDB MCP
Provides tools for interacting with MongoDB databases, including listing collections, fetching schemas, and performing CRUD operations (insert, update, delete, find) on documents.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MongoDB MCP show me the users collection schema"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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
Related MCP server: MongoDB MCP Server
Using pip
pip install mongo-mcpUsing uv
uv add mongo-mcpPrerequisites
Python 3.10+
MongoDB Local Instance or MongoDB Atlas Cluster
Examples:
mongodb://localhost:27017or
mongodb+srv://username:password@cluster.mongodb.netConfiguration
MongoDB MCP uses environment variables to connect to your database.
Create a .env file:
MONGODB_URI=mongodb://localhost:27017
DATABASE_NAME=shipbiharEnvironment Variables
Variable | Description | Required |
MONGODB_URI | MongoDB connection string | Yes |
DATABASE_NAME | Database name | Yes |
Running the MCP Server
mongo_mcpor
python -m mongo_mcp.mainThe 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_nameor 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:
ServerSelectionTimeoutErrorReason:
MongoDB server is not running.
Solution:
Start MongoDB:
mongodor verify your Atlas connection string.
Error: Authentication Failed
Error:
Authentication failedReason:
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 GitHubHardcode MongoDB passwords in code
Development
Clone the repository:
git clone <repository-url>
cd mongo-mcpCreate environment:
uv venv
source .venv/bin/activateInstall dependencies:
uv syncRun locally:
python -m mongo_mcp.mainRoadmap
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
Available Tools
8 toolsall_collectionsA
Returns all collections in the database.
Inputs: no named parameters.
count_documentsC
Count matching documents.
Inputs: collection_name (required), query.
delete_documentC
Delete matching document.
Inputs: filter_query (required), collection_name (required).
fetch_collection_dataC
Fetch documents from a collection.
Inputs: collection_name (required), limit.
fetch_collection_schemaB
Returns inferred schema from a sample document.
Inputs: collection_name (required).
find_documentC
Find a single document.
Inputs: query (required), collection_name (required).
insert_documentC
Insert a document.
Inputs: document (required), collection_name (required).
update_documentC
Update matching document.
Inputs: update_data (required), filter_query (required), collection_name (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Most tools are clearly distinct: collection listing, schema inference, data fetching, single document find, count, insert, update, delete. The only potential overlap is between fetch_collection_data and find_document, but the former implies multiple documents while the latter explicitly targets a single document.
The naming mixes patterns: 'all_collections' and 'fetch_collection_*' vs. 'find_document', 'count_documents', 'insert_document', etc. While verb-first naming is used for most, the prefixes 'all' and 'fetch_collection_' are inconsistent. Still readable and not chaotic.
With 8 tools, the server covers the core MongoDB operations without unnecessary bloat. Each tool serves a clear purpose in the database workflow, from listing collections to CRUD operations and schema inspection.
The tool set provides comprehensive coverage for basic MongoDB interactions: listing collections, inspecting schemas, querying documents, counting, inserting, updating, and deleting. Missing advanced features like aggregation or indexing are not critical for a general-purpose MongoDB MCP server.
Maintenance
Related MCP Connectors
MCP server for building and testing AI agents with multi-model experimentation and insights.
One MCP server for the services your AI needs: memory, files, Microsoft 365, kanban and more.
The Remote MCP server acts as a standardized bridge between LLM applications (like Claude, ChatGPT, and Cursor) and external services, enabling AI agents to access external tools and resources. Its primary capability is providing a centralized search tool to discover other MCP servers and their respective tools. Unlike local implementations, it runs remotely with OAuth authentication and permission controls for security.
MCP server connecting AI agents to 100+ apps (Gmail, Slack, Notion, GitHub) via one-click OAuth.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server that enables large language models to interact directly with MongoDB databases, allowing them to query collections, inspect schemas, and manage data through natural language.23 npmMIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server for MongoDB operations, enabling AI assistants to interact with MongoDB databases through a standardized interface.21 npm6MIT
- AlicenseNot gradedqualityCmaintenanceMCP server for comprehensive MongoDB integration, enabling database operations, document management, schema analysis, and query tools.20 npmMIT
- AlicenseNot gradedqualityDmaintenanceFeature-rich MCP server for MongoDB with multi-connection support, enabling users to interact with multiple MongoDB clusters simultaneously, perform CRUD operations, run aggregations, diagnostics, and more, all through natural language.6 npmMIT