- Explore MCP Servers
- mongo-mcp
Mongo Mcp
What is Mongo Mcp
mongo-mcp is a Machine Chat Protocol (MCP) service designed for MongoDB operations. It provides a set of tools that enable large language models (LLMs) to interact with MongoDB databases through basic CRUD operations and management tasks.
Use cases
Use cases for mongo-mcp include integrating with chatbots that need to store and retrieve user data, applications that require real-time data manipulation in MongoDB, and any system that benefits from automated database management through a conversational interface.
How to use
To use mongo-mcp, clone the repository from GitHub, navigate to the project directory, and install the package using pip. You can start the MCP server directly or configure it using environment variables to set the MongoDB connection string and other options.
Key features
Key features include MongoDB instance connection management, listing databases and collections, performing CRUD operations (insert, query, update, delete), full support for MongoDB query syntax and projection operations, robust error handling and logging, and a standard input/output (stdio) based MCP transport implementation.
Where to use
mongo-mcp can be used in various fields that require database management and interaction, particularly in applications involving large language models, data analysis, and backend services that utilize MongoDB as a database solution.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Mongo Mcp
mongo-mcp is a Machine Chat Protocol (MCP) service designed for MongoDB operations. It provides a set of tools that enable large language models (LLMs) to interact with MongoDB databases through basic CRUD operations and management tasks.
Use cases
Use cases for mongo-mcp include integrating with chatbots that need to store and retrieve user data, applications that require real-time data manipulation in MongoDB, and any system that benefits from automated database management through a conversational interface.
How to use
To use mongo-mcp, clone the repository from GitHub, navigate to the project directory, and install the package using pip. You can start the MCP server directly or configure it using environment variables to set the MongoDB connection string and other options.
Key features
Key features include MongoDB instance connection management, listing databases and collections, performing CRUD operations (insert, query, update, delete), full support for MongoDB query syntax and projection operations, robust error handling and logging, and a standard input/output (stdio) based MCP transport implementation.
Where to use
mongo-mcp can be used in various fields that require database management and interaction, particularly in applications involving large language models, data analysis, and backend services that utilize MongoDB as a database solution.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
Mongo-MCP
English | 简体中文
A Machine Chat Protocol (MCP) service for MongoDB operations. This service provides a comprehensive set of tools that allow Large Language Models (LLMs) to interact with MongoDB databases through complete CRUD operations, administrative tasks, and advanced features.
Requirements
- Python 3.10 or above
- A running MongoDB database service
- It is recommended to use uv to run the program
🚀 Features
📊 Database Management Tools
list_databases
- List all databasescreate_database
- Create new databasedrop_database
- Delete databaseget_database_stats
- Get database statistics
📦 Collection Management Tools
list_collections
- List all collections in a databasecreate_collection
- Create new collection (with optional settings)drop_collection
- Delete collectionrename_collection
- Rename collectionget_collection_stats
- Get collection statistics
📄 Document CRUD Operations
insert_document
- Insert single documentinsert_many_documents
- Batch insert multiple documentsfind_documents
- Query documents (supports sorting, projection, limit)find_one_document
- Query single documentcount_documents
- Count documents matching queryupdate_document
- Update documents (single or batch)replace_document
- Replace documentdelete_document
- Delete documents (single or batch)
🔍 Index Management Tools
list_indexes
- List all indexes for a collectioncreate_index
- Create regular indexcreate_text_index
- Create text search indexcreate_compound_index
- Create compound indexdrop_index
- Delete indexreindex_collection
- Rebuild all indexes for a collection
📈 Aggregation Operations
aggregate_documents
- Execute aggregation pipeline operationsdistinct_values
- Get distinct values for a field
🔧 Monitoring and Administrative Tools
get_server_status
- Get MongoDB server statusget_replica_set_status
- Get replica set statusping_database
- Test database connectiontest_mongodb_connection
- Comprehensive connection testget_connection_details
- Get detailed connection information
🛠️ Technology Stack
- Python: Primary programming language
- FastMCP: MCP Python SDK for automatic tool definition generation
- PyMongo: Official MongoDB Python driver
- uv: Modern Python package management tool
Usage
Run directly with uvx
uvx run mongo-mcp
The server uses the stdio transport method, making it suitable for integration with MCP clients that support this transport method.
Cursor Example Configuration
If you use Cursor as your development environment, you can add the following configuration to your .cursor/mcp.json
file for local debugging:
{
"mcpServers": {
"mongo-mcp": {
"command": "uvx",
"args": [
"mongo-mcp"
],
"env": {
"MONGODB_URI": "mongodb://localhost:27017",
"MONGODB_DEFAULT_DB": "your_database_name",
"LOG_LEVEL": "INFO"
}
}
}
}
Environment Variables
Basic Configuration
MONGODB_URI
: MongoDB connection string (default: “mongodb://localhost:27017”)MONGODB_DEFAULT_DB
: Default database name (optional)
Connection Pool Configuration
MONGODB_MIN_POOL_SIZE
: Minimum connection pool size (default: 0)MONGODB_MAX_POOL_SIZE
: Maximum connection pool size (default: 100)MONGODB_MAX_IDLE_TIME_MS
: Maximum idle time in milliseconds (default: 30000)
Timeout Configuration
MONGODB_SERVER_SELECTION_TIMEOUT_MS
: Server selection timeout (default: 30000)MONGODB_SOCKET_TIMEOUT_MS
: Socket timeout (default: 0 - no timeout)MONGODB_CONNECT_TIMEOUT_MS
: Connection timeout (default: 20000)
Security Configuration
MONGODB_TLS_ENABLED
: Enable TLS connection (default: false)MONGODB_AUTH_SOURCE
: Authentication source (default: admin)MONGODB_AUTH_MECHANISM
: Authentication mechanism (SCRAM-SHA-1, SCRAM-SHA-256, etc.)
Performance Settings
MONGODB_READ_PREFERENCE
: Read preference (default: primary)MONGODB_WRITE_CONCERN_W
: Write concern (default: 1)MONGODB_READ_CONCERN_LEVEL
: Read concern level (default: local)
Logging Configuration
LOG_LEVEL
: Logging level (default: “INFO”)- Available values: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_MAX_FILE_SIZE
: Maximum log file size in bytes (default: 10MB)LOG_BACKUP_COUNT
: Number of backup log files (default: 5)
Feature Flags
ENABLE_DANGEROUS_OPERATIONS
: Enable potentially dangerous operations (default: false)ENABLE_ADMIN_OPERATIONS
: Enable administrative operations (default: true)ENABLE_INDEX_OPERATIONS
: Enable index operations (default: true)
Development Guide
- Clone the repository
git clone https://github.com/441126098/mongo-mcp.git
cd mongo-mcp
- Install development dependencies
# Using uv (recommended)
uv sync
# Or using pip
pip install -e ".[dev]"
- Run tests
uv run pytest tests/ -v
- Code Structure
src/mongo_mcp/server.py
: MCP server implementationsrc/mongo_mcp/db.py
: Core MongoDB operations implementationsrc/mongo_mcp/config.py
: Configuration managementsrc/mongo_mcp/tools/
: MCP tools implementationdatabase_tools.py
: Database and collection managementdocument_tools.py
: Document CRUD operationsindex_tools.py
: Index managementaggregation_tools.py
: Aggregation operationsadmin_tools.py
: Administrative and monitoring tools
src/mongo_mcp/utils/
: Utility modulestests/
: Test cases
Testing
The project includes comprehensive test coverage:
- Unit tests for all tool modules
- Integration tests with MongoDB
- Mock tests for isolated component testing
Run the test suite:
# Run all tests
uv run pytest
# Run with verbose output
uv run pytest -v
# Run specific test file
uv run pytest tests/test_tools.py
Logging
Log files are stored in the logs
directory by default. The logging system supports:
- Configurable log levels
- File rotation based on size
- UTF-8 encoding support
- Structured logging with function names and line numbers
License
MIT
Contributing
Contributions via Issues and Pull Requests are welcome. Before submitting a PR, please ensure:
- All tests pass (
uv run pytest
) - Appropriate test cases are added
- Documentation is updated
- Code follows the existing style patterns
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.