Optional integration for AI-powered responses and context-aware conversation capabilities within the Telegram bot.
Enables sending messages to Telegram chats, retrieving chat and bot information, broadcasting to users, and managing conversation history. Provides MCP tools for message sending, chat operations, and access to recent messages, active users, and bot statistics.
Telegram Bot MCP
A Telegram bot powered by FastMCP (Model Context Protocol) that enables AI integration and bot functionality. Available in both simple and full-featured variants to suit different use cases.
π¦ Smithery Deployment
You can install this MCP server via Smithery:
π Simple Telegram Bot MCP (simple_telegram_bot_mcp.py)
Perfect for basic message sending and simple integrations
β¨ Features
Minimal Setup: Single file with just message sending functionality
FastMCP Server: Exposes
send_telegram_messagetool via MCP protocolLightweight: Perfect for basic notification needs and simple integrations
Quick Start: Requires only bot token and chat ID to get started
Streamable HTTP: Runs on configurable port with streamable HTTP transport
π Requirements (Simple Version)
Python 3.10+
Telegram Bot Token (from @BotFather)
Chat ID where messages will be sent
π οΈ Installation (Simple Version)
Clone the repository:
git clone https://github.com/your-username/telegram-bot-mcp.git cd telegram-bot-mcpInstall dependencies:
pip install fastmcp python-dotenv requestsSet up environment variables:
TELEGRAM_BOT_TOKEN=your_bot_token_here TELEGRAM_CHAT_ID=your_chat_id_here
π Quick Start (Simple Version)
π§ MCP Tool (Simple Version)
The simple bot exposes one MCP tool:
send_telegram_message(text: str): Send a message to the configured Telegram chat
π³ Docker Usage (Simple Version)
π’ Full-Featured Telegram Bot MCP (telegram_bot_mcp.py)
Complete solution with advanced features and production capabilities
π Features (Full Version)
FastMCP Integration: Built with FastMCP framework for seamless AI model integration
Multiple Deployment Modes: Supports polling, webhook, and combined modes
MCP Tools & Resources: Expose Telegram functionality as MCP tools and resources
AI-Powered Responses: Context-aware intelligent responses
User Management: Track users, sessions, and conversation history
Production Ready: FastAPI webhook server for production deployment
Comprehensive Logging: Detailed logging and monitoring capabilities
Flexible Configuration: Environment-based configuration management
π Requirements (Full Version)
Python 3.10+
Telegram Bot Token (from @BotFather)
Optional: AI API keys (OpenAI, Anthropic) for enhanced features
π οΈ Installation
Clone the repository:
git clone https://github.com/your-username/telegram-bot-mcp.git cd telegram-bot-mcpInstall dependencies:
pip install -r requirements.txtSet up environment variables:
cp env.example .env # Edit .env file with your configurationConfigure your bot token:
Create a bot with @BotFather
Copy the token to your
.envfile
βοΈ Configuration
Create a .env file based on env.example:
π Quick Start
Method 1: Using the Unified Starter (Recommended)
Method 2: Individual Components
ποΈ Architecture
π Project Structure
π§ MCP Integration
This bot exposes several MCP tools and resources:
Tools
send_telegram_message: Send messages to Telegram chatsget_chat_info: Get information about Telegram chatsbroadcast_message: Send messages to all known usersget_bot_info: Get bot information and capabilities
Resources
telegram://messages/recent/{limit}: Get recent messagestelegram://users/active: Get list of active userstelegram://stats/summary: Get bot statistics
Prompts
create_welcome_message: Generate welcome messagesgenerate_help_content: Create help documentation
π€ Bot Commands
/start- Initialize bot and show welcome message/help- Display help information/info- Show user profile and session info/stats- View bot statistics/clear- Clear conversation history
π Deployment
Development (Polling Mode)
Production (Webhook Mode)
Set up your domain and SSL certificate
Configure webhook URL:
export TELEGRAM_WEBHOOK_URL=https://your-domain.com/webhookStart the server:
python start.py --webhook
Docker Deployment (Optional)
Create a Dockerfile:
Required configuration:
telegramBotToken: Your Telegram Bot API token from @BotFathertelegramChatId: The chat ID where messages will be sent
π API Endpoints
When running in webhook mode, the following endpoints are available:
GET /- Server informationGET /health- Health checkPOST /webhook- Telegram webhookGET /bot/info- Bot informationGET /mcp/status- MCP server statusGET /stats- Server statistics
π Monitoring
The bot provides comprehensive logging and monitoring:
Health checks:
/healthendpointStatistics: User activity, message counts, command usage
Logging: Structured logging with configurable levels
Error tracking: Detailed error reporting
π‘οΈ Security
Webhook verification: Optional signature verification
Environment variables: Secure configuration management
Input validation: Pydantic models for data validation
Error handling: Graceful error handling and logging
π§ Customization
Adding New Commands
Edit bot_runner.py and add new command handlers:
Adding MCP Tools
Edit telegram_bot_mcp.py and add new tools:
Custom AI Integration
The bot can be integrated with various AI models through the MCP protocol. Add your AI processing logic in the _process_with_mcp method.
π Troubleshooting
Common Issues
Bot token not working:
Verify token with @BotFather
Check
.envfile configuration
Webhook not receiving updates:
Verify webhook URL is accessible
Check SSL certificate
Review server logs
MCP server connection issues:
Ensure MCP server is running
Check port configuration
Verify firewall settings
Debug Mode
Enable debug mode for detailed logging:
π Logging
Logs are structured and include:
Timestamp
Log level
Component name
Message details
Configure logging level via environment variable:
π€ Contributing
Fork the repository
Create a feature branch
Add tests for new functionality
Submit a pull request
π License
This project is licensed under the MIT License. See LICENSE file for details.
π Acknowledgments
FastMCP - FastMCP framework
python-telegram-bot - Telegram Bot API wrapper
FastAPI - Modern web framework
Built with β€οΈ using FastMCP and Python