lamchantuong/dynamic-mcp
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.
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
- Python 3.10+ (required by MCP library): https://modelcontextprotocol.io/quickstart/server?utm_source=chatgpt.com#system-requirements
- Optional: SQL Server + ODBC Driver 17 (only if using
pyodbc_tools.py) - Optional: Any other dependencies for your custom tools
🛠️ Installation
-
Clone the repository
git clone <repository-url> cd dynamic-mcp -
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 -
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)
-
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] }]) -
pyodbc_default_config: Get current database configuration
pyodbc_default_config()
HTTP Tools (requests_tools.py)
- 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
- Server starts and scans the
tools/directory - Finds all Python files (except
__init__.py) - Imports each module and looks for
register_tools()function - Registers all tools found in each module
- 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
- Create a new Python file in the
tools/directory - Implement a
register_tools(mcp: FastMCP, config: dict)function - Use the
@mcp.tool()decorator to register your functions - 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
-
Python Version Error
- Ensure Python 3.10+ is installed (required by MCP library)
- Check version with:
python --version - Download from: https://www.python.org/downloads/
-
Database Connection Failed
- Check your database configuration in
tools_config.yml - Ensure SQL Server is running and accessible
- Verify ODBC Driver 17 is installed
- Check your database configuration in
-
Tool Registration Failed
- Check that your tool file has a
register_toolsfunction - Ensure all dependencies are installed
- Check the logs for specific error messages
- Check that your tool file has a
-
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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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.