Mongo-MCP

by 441126098

Not rated
GitHub

About

An MCP server for interacting with a MongoDB database.

Details

Author
441126098
Categories
Database, Other
Tags
#mongodb

Setup

Install Mongo-MCP in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/441126098/mongo-mcp

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

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.

- Python 3.10 or above
- A running MongoDB database service
- It is recommended to useuvto run the program

- list_databases- List all databases
- create_database- Create new database
- drop_database- Delete database
- get_database_stats- Get database statistics

- list_collections- List all collections in a database
- create_collection- Create new collection (with optional settings)
- drop_collection- Delete collection
- rename_collection- Rename collection
- get_collection_stats- Get collection statistics

- insert_document- Insert single document
- insert_many_documents- Batch insert multiple documents
- find_documents- Query documents (supports sorting, projection, limit)
- find_one_document- Query single document
- count_documents- Count documents matching query
- update_document- Update documents (single or batch)
- replace_document- Replace document
- delete_document- Delete documents (single or batch)

- list_indexes- List all indexes for a collection
- create_index- Create regular index
- create_text_index- Create text search index
- create_compound_index- Create compound index
- drop_index- Delete index
- reindex_collection- Rebuild all indexes for a collection

- aggregate_documents- Execute aggregation pipeline operations
- distinct_values- Get distinct values for a field

- get_server_status- Get MongoDB server status
- get_replica_set_status- Get replica set status
- ping_database- Test database connection
- test_mongodb_connection- Comprehensive connection test
- get_connection_details- Get detailed connection information

- Python: Primary programming language
- FastMCP: MCP Python SDK for automatic tool definition generation
- PyMongo: Official MongoDB Python driver
- uv: Modern Python package management tool

The server uses the stdio transport method, making it suitable for integration with MCP clients that support this transport method.

If you useCursoras your development environment, you can add the following configuration to your.cursor/mcp.jsonfile 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" } } } }

- MONGODB_URI: MongoDB connection string (default: "mongodb://localhost:27017")
- MONGODB_DEFAULT_DB: Default database name (optional)

- 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)

- 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)

- 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.)

- MONGODB_READ_PREFERENCE: Read preference (default: primary)
- MONGODB_WRITE_CONCERN_W: Write concern (default: 1)
- MONGODB_READ_CONCERN_LEVEL: Read concern level (default: local)

- LOG_LEVEL: Logging level (default: "INFO")

- Available values: DEBUG, INFO, WARNING, ERROR, CRITICAL

- 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)

git clone https://github.com/441126098/mongo-mcp.git cd mongo-mcp
# Using uv (recommended) uv sync # Or using pip pip install -e ".[dev]"

- src/mongo_mcp/server.py: MCP server implementation
- src/mongo_mcp/db.py: Core MongoDB operations implementation
- src/mongo_mcp/config.py: Configuration management
- src/mongo_mcp/tools/: MCP tools implementation

- database_tools.py: Database and collection management
- document_tools.py: Document CRUD operations
- index_tools.py: Index management
- aggregation_tools.py: Aggregation operations
- admin_tools.py: Administrative and monitoring tools

The project includes comprehensive test coverage:

- Unit tests for all tool modules
- Integration tests with MongoDB
- Mock tests for isolated component testing

# 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

Log files are stored in thelogsdirectory 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

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

Update various databases (PostgreSQL, MySQL, MongoDB, SQLite) using data from CSV and Excel files.

Connects to and interacts with various database systems like SQLite, PostgreSQL, SQL Server, and MongoDB.

An MCP server that enables LLMs to interact with databases like MongoDB using natural language.

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.

Interact with MongoDB databases and MongoDB Atlas.

A server for interacting with MongoDB databases and MongoDB Atlas.

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

A server for performing CRUD operations on a MongoDB database.

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.