dynamic-mcp

lamchantuong/dynamic-mcp

3.1

If you are the rightful owner of dynamic-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Dynamic MCP Server is a flexible and adaptable server designed to automatically discover and register custom tools, allowing for seamless integration and modification without altering the core server code.

Tools
2
Resources
0
Prompts
0

Dynamic MCP Server

A flexible Model Context Protocol (MCP) server that automatically discovers and registers custom tools from the tools/ directory. This server is designed to be truly dynamic - you can add, remove, or modify tools without changing the core server code.

🚀 Features

  • 🔄 Dynamic Tool Discovery: Automatically discovers and registers tools from the tools/ directory
  • ➕ Easy Tool Addition: Simply add a new Python file to tools/ and it's automatically registered
  • 🗑️ Flexible Tool Removal: Remove any tool by deleting its file - no server restart needed
  • 🔧 Customizable: Add your own tools for any purpose (database, APIs, file operations, etc.)
  • 📦 Pre-built Tools: Includes database operations (pyodbc) and HTTP requests out of the box
  • 🚀 Multiple Transports: Support for stdio, HTTP, SSE, and streamable-http transports
  • 📝 Configurable Logging: Flexible logging with file and console output
  • 🛡️ Error Handling: Comprehensive error handling with structured responses

📋 Prerequisites

🛠️ Installation

  1. Clone the repository

    git clone <repository-url>
    cd dynamic-mcp
    
  2. Install dependencies

    # Install core dependencies
    pip install mcp PyYAML
    
    # Or install all dependencies (including optional ones)
    pip install -r requirements.txt
    
    # Or install only what you need:
    # pip install mcp PyYAML pyodbc  # For database tools
    # pip install mcp PyYAML requests  # For HTTP tools
    
  3. Configure the server (optional)

    # Copy example configuration files
    cp config.example.yml config.yml
    
    # Only copy tools config if you plan to use database tools
    cp tools_config.example.yml tools_config.yml
    
    # Edit configuration files with your settings
    nano config.yml
    # nano tools_config.yml  # Only if using database tools
    

⚙️ Configuration

Server Configuration (config.yml)

# Server Configuration
server:
  name: "dynamic-mcp"
  port: 5001                          # Only used for HTTP transports
  host: "127.0.0.1"                  # Only used for HTTP transports

# Server Runtime Configuration
server-runtime:
  transport: "http"                   # Options: stdio, sse, streamable-http, http

# Logging Configuration
logging:
  level: "INFO"                       # DEBUG, INFO, WARNING, ERROR, CRITICAL
  log_to_file: false                  # Write logs to file
  log_to_console: true                # Display logs on console

Tools Configuration (tools_config.yml)

# Database Configuration
database:
  server: "localhost\\sql2022,1433"  # SQL Server instance
  database: "Test"                    # Database name
  username: "sa"                      # Username
  password: "your_password"           # Password
  driver: "{ODBC Driver 17 for SQL Server}"  # ODBC Driver

🚀 Usage

Starting the Server

python scripts/main.py

The server will start and automatically register all available tools. You'll see output like:

🚀 MCP server starting on 127.0.0.1:5001 | Transport: streamable-http
Tool registered successfully: pyodbc_tools.py
Tool registered successfully: requests_tools.py

Available Tools

Database Tools (pyodbc_tools.py)
  1. pyodbc_execute: Execute SQL queries

    # Single query
    pyodbc_execute("SELECT * FROM users")
    
    # Multiple queries
    pyodbc_execute([
        "INSERT INTO users (name, age) VALUES ('Alice', 30)",
        "SELECT COUNT(*) FROM users"
    ])
    
    # Parameterized queries
    pyodbc_execute([{
        "sql": "SELECT * FROM users WHERE age > ?",
        "params": [25]
    }])
    
  2. pyodbc_default_config: Get current database configuration

    pyodbc_default_config()
    
HTTP Tools (requests_tools.py)
  1. requests_fetch: Make HTTP requests
    # GET request
    requests_fetch("https://api.example.com/data")
    
    # POST request with JSON
    requests_fetch(
        url="https://api.example.com/users",
        method="POST",
        json_data={"name": "John", "email": "john@example.com"}
    )
    
    # Request with headers and parameters
    requests_fetch(
        url="https://api.example.com/search",
        method="GET",
        headers={"Authorization": "Bearer token"},
        params={"q": "search term"}
    )
    

🏗️ Architecture

dynamic-mcp/
├── scripts/
│   └── main.py              # Main server entry point
├── tools/                   # 🔄 Dynamic tool modules (auto-registered)
│   ├── pyodbc_tools.py     # Database tools (optional)
│   ├── requests_tools.py   # HTTP tools (optional)
│   └── your_custom_tools.py # ✨ Your custom tools here!
├── utils/                   # Utility functions
│   └── utils.py            # Logging, config loading, etc.
├── config.yml              # Server configuration
├── tools_config.yml        # Tools configuration (optional)
└── requirements.txt        # Python dependencies

🔄 How Dynamic Registration Works

  1. Server starts and scans the tools/ directory
  2. Finds all Python files (except __init__.py)
  3. Imports each module and looks for register_tools() function
  4. Registers all tools found in each module
  5. Reports success/failure for each tool registration

Result: You can add/remove tools by simply adding/removing files - no server code changes needed!

🔧 Adding Custom Tools

The server is designed to be truly dynamic! You can easily add your own tools:

Quick Start

  1. Create a new Python file in the tools/ directory
  2. Implement a register_tools(mcp: FastMCP, config: dict) function
  3. Use the @mcp.tool() decorator to register your functions
  4. That's it! The tool will be automatically discovered and registered on server startup

Removing Tools

  • Delete the tool file from tools/ directory
  • Restart the server - the tool will be automatically removed
  • No code changes needed!

Tool Ideas

  • File operations (read, write, copy, move)
  • API integrations (REST, GraphQL)
  • Database operations (PostgreSQL, MySQL, MongoDB)
  • System commands (shell execution)
  • Data processing (CSV, JSON, XML)
  • Image processing
  • Email sending
  • And much more!

🐛 Troubleshooting

Common Issues

  1. Python Version Error

  2. Database Connection Failed

    • Check your database configuration in tools_config.yml
    • Ensure SQL Server is running and accessible
    • Verify ODBC Driver 17 is installed
  3. Tool Registration Failed

    • Check that your tool file has a register_tools function
    • Ensure all dependencies are installed
    • Check the logs for specific error messages
  4. Server Won't Start

    • Verify configuration files are valid YAML
    • Check that the port is not already in use
    • Ensure all required dependencies are installed

Logs

Logs are written to the logs/ directory by default (if log_to_file: true). Check these files for detailed error information.

📝 License

This project is licensed under the MIT License - see the file for details.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📞 Support

If you encounter any issues or have questions, please open an issue on GitHub.


Note: Make sure to keep your configuration files secure and never commit sensitive information like passwords or API keys to version control.