MCP Server - Modular Architecture
This MCP (Model Context Protocol) server is built with a clean, modular architecture for maintainable, scalable, and robust development.
๐ Project Structure
๐ Quick Start
Install dependencies:
pip install -r requirements.txtCreate environment file:
# Create .env file with your configuration TG_TOKEN=your_telegram_bot_token ADMIN_ID=your_telegram_chat_idRun the server:
python main.py
๐ Available Tools
Basic Tools
echoโ Echo back input text
File Tools
read_fileโ Read the contents of a filewrite_fileโ Write content to a filecreate_fileโ Create a new empty filecreate_folderโ Create a new directorylist_filesโ List files and folders in a directorydelete_fileโ Delete a filerename_fileโ Rename or move a filemove_folderโ Move a folder (directory) to a new location
System Tools
system_infoโ Get basic system information (platform, memory, CPU, etc.)list_processesโ List running processes (PID, name, user)run_python_codeโ Execute a Python code snippet and return the outputinstall_python_libraryโ Install a Python library (via pip) and update requirements.txt
Telegram Integration
send_telegram_messageโ Send Telegram messages, audio, video, or documents (with optional metadata)receive_telegram_updatesโ Receive and download incoming Telegram messages and files
Scheduling & Job Tools (still in testing)
schedule_telegram_messageโ Schedule a Telegram message to be sent at a specific time (supports ISO datetime or relative times like "in 10 minutes")schedule_function_callโ Schedule any registered function to run once at a specified timeschedule_recurring_jobโ Schedule recurring jobs using cron expressions or intervals (e.g., "every 5 minutes", "0 9 ** 1-5")list_scheduled_jobsโ List all currently scheduled jobs with detailscancel_scheduled_jobโ Cancel a scheduled job by its IDget_available_functionsโ List all functions available for schedulingget_job_execution_logโ View the execution history and results of scheduled jobs
Persistence Tools
update_persistent_infoโ Add or update a key-value pair in persistent storageget_persistent_infoโ Retrieve all persistent data, or a specific key's valuedelete_persistent_info_keyโ Delete a key from persistent storage
Control Tools
type_textโ Simulate typing text using the keyboardpress_hotkeyโ Press a combination of keys as a hotkey (e.g., Ctrl+Tab)switch_to_windowโ Switch focus to a window with a specified titlelist_open_windowsโ List the titles of all currently open windowsmove_mouse_toโ Move the mouse cursor to specified screen coordinatesclick_mouseโ Click the mouse at specified coordinates or at the current position
YouTube Tools
youtube_download_videoโ Download a YouTube video as MP4youtube_download_audioโ Download YouTube audio as MP3youtube_video_infoโ Get detailed YouTube video information
๐ง Architecture Benefits
Separation of Concerns
config.py: Centralized configuration
persistence.py: Data storage abstraction
scheduler.py: Scheduling logic isolated
tools/: Tools organized by functionality
Maintainability
Add new tools by creating new modules
Clear dependencies between components
Consistent error handling and logging
Scalability
Modular design for easy extension
Shared MCP instance prevents conflicts
Function registry enables dynamic scheduling
๐ Data Persistence
The server automatically persists:
Scheduled Jobs: Survives server restarts
Execution Logs: Detailed job run history
Persistent Info: Custom key-value storage
Files created:
scheduled_jobs.jsonโ Job definitionsjob_execution_log.jsonโ Execution historypersistent_info.jsonโ Custom datamain.logโ Application logserror.logโ Error logs
๐ ๏ธ Development
Adding New Tools
Create a new module in
tools/Import the shared MCP instance:
from . import mcpDefine your tool function with
@mcp.tool()decoratorRegister the function in
tools/__init__.pyif needed
Adding New Persistence Functions
Add functions to
persistence.pyImport and use them in your tools
Follow the existing pattern for error handling
๐ Troubleshooting
Check logs in
main.loganderror.logVerify environment variables in
.envEnsure all dependencies are installed
Check file permissions for persistence
This server cannot be installed