Labsco
441126098 logo

Mongo-MCP

โ˜… 3

from 441126098

An MCP server for interacting with a MongoDB database.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

Mongo-MCP

smithery badge 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.

๐Ÿš€ Features

๐Ÿ“Š Database Management Tools

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

๐Ÿ“ฆ Collection Management Tools

  • 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

๐Ÿ“„ Document CRUD Operations

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

๐Ÿ” Index Management Tools

  • 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

๐Ÿ“ˆ Aggregation Operations

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

๐Ÿ”ง Monitoring and Administrative Tools

  • 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

๐Ÿ› ๏ธ 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

Development Guide

  1. Clone the repository
git clone https://github.com/441126098/mongo-mcp.git
cd mongo-mcp
  1. Install development dependencies
# Using uv (recommended)
uv sync

# Or using pip
pip install -e ".[dev]"
  1. Run tests
uv run pytest tests/ -v
  1. Code Structure
  • 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
  • src/mongo_mcp/utils/: Utility modules
  • tests/: 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