Enables AI assistants to send questions and notifications to users via Telegram, supporting clickable buttons and wait-for-response workflows to facilitate human-in-the-loop decision making.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Telegram MCP ServerAsk me on Telegram for approval before starting the production deployment."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Telegram MCP Server
A Model Context Protocol (MCP) server that enables AI assistants (like Kilo Code) to ask you questions via Telegram and wait for your responses. This creates a "human-in-the-loop" workflow where the AI can request decisions, approvals, or specific input during long-running tasks.
Features
๐ค Interactive AI Workflow: AI can pause and ask you questions via Telegram
๐ฑ Button Support: Present multiple choice options as clickable buttons
โฑ๏ธ Long Polling: Waits up to 2 minutes for your response
๐ Secure: Uses environment variables for credentials
๐ฏ Simple Integration: Works with any MCP-compatible AI assistant
๐ณ Docker Support: Run natively or in a container
Prerequisites
Python 3.10+ (for native installation)
OR Docker and Docker Compose (for containerized installation)
A Telegram account
A Telegram Bot Token (from @BotFather)
Installation Methods
You can run this MCP server in two ways:
Native Python Installation - Run directly on your system
Docker Installation - Run in a container (recommended for production)
Native Installation
1. Create a Telegram Bot
Open Telegram and search for @BotFather
Send
/newbotand follow the promptsName your bot (e.g., "MyDevBot")
Copy the HTTP API Token provided
Important: Send
/startto your new bot so it can message you
2. Find Your Telegram User ID (Optional)
Search for @userinfobot on Telegram
Send it any message
Copy your User ID
3. Clone and Setup
4. Configuration
Create a .env file from the sample:
Edit .env and add your credentials:
โ ๏ธ Security Note: The .env file is gitignored to protect your credentials.
5. Test the Server Locally
You should see:
Press Ctrl+C to stop the test.
Docker Installation
1. Configure Environment
2. Build and Run
3. View Logs
4. Stop the Server
Docker Commands Reference
Building:
Running:
Monitoring:
Stopping and Cleaning:
Restart:
Development:
Connecting to MCP Clients
For Kilo Code (or similar MCP clients)
Method 1: Using the Startup Script (Recommended)
Open your MCP settings file:
Location:
~/.config/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcpSettings.jsonOr use your client's UI: Settings โ MCP Servers โ Edit Configuration
Add this configuration (replace ):
Example: If you cloned to /home/user/projects/telegram-mcp-server, use:
Restart your MCP client or reload the MCP servers
Note: An example configuration is provided in mcp-config.example.json for reference.
Method 2: Direct Python Execution
Method 3: Using Docker
Option A: Docker Compose Exec
Option B: Docker Run
Available Tools
Once connected, your AI assistant will have access to these tools:
ask_human(question, options, wait, timeout_seconds, allow_custom) - Send questions to Telegram
wait=True(default): Blocks until you respond or timeoutwait=False: Sends question and returns immediately (non-blocking mode)options: Optional list of button choicesallow_custom=True(default): Adds "Custom answer" button when options providedWorks in both blocking and non-blocking modes
get_telegram_response(mark_as_read) - Retrieve your latest Telegram message
Use after
ask_human(wait=False)to get your responsemark_as_read=True(default): Won't retrieve the same message twice
send_telegram_notification(message) - Send one-way status updates
For progress reports, completion notifications, or status updates
Doesn't expect a response
Perfect for keeping you informed during long-running tasks
list_telegram_messages(limit) - View recent conversation history
Shows last 5-20 messages for context
Useful for checking if you've already replied
Usage Examples
Example 1: Simple Question
You say to your AI:
"I'm going to grab coffee. If you need to know which database to use, ask me via Telegram."
AI calls:
What happens:
Your phone buzzes with a Telegram message
You reply: "PostgreSQL"
AI receives "PostgreSQL" and continues
Example 2: Multiple Choice with Buttons
AI calls:
What happens:
You receive a Telegram message with 4 clickable buttons
You tap "JWT"
AI receives "JWT" instantly
Example 3: Approval Workflow
You say to your AI:
"Refactor the entire codebase, but ask me before making any breaking changes."
AI calls:
Example 4: Non-Blocking Mode for Complex Questions
AI asks without waiting:
What happens:
You receive the question on Telegram
You take your time to review (no timeout)
When ready, you tell the AI: "I've answered on Telegram"
AI retrieves your answer:
get_telegram_response()
Example 5: Progress Notifications
AI sends status updates:
How It Works
AI calls with a question and optional button choices
Server sends Telegram message to your configured chat
Long polling loop checks Telegram every 2 seconds for your response
You respond via text or button click
Server returns your answer to the AI
AI continues with your input
Timeout Behavior
Default timeout: 120 seconds (2 minutes)
Configurable via the
timeout_secondsparameter inask_human()If you don't respond in time, the AI receives:
"Timeout: User did not respond in time..."
Non-Blocking Mode
For complex questions that require extended thinking time, use non-blocking mode to avoid timeouts:
AI asks without waiting:
ask_human("Please review this architecture and provide feedback", wait=False)You receive the question and can take as long as needed to think and respond
When ready, tell the AI you've replied:
"I've answered on Telegram"
AI retrieves your answer:
answer = get_telegram_response()
Custom Answers with Buttons
When you provide button options, the AI automatically adds a "โ๏ธ Custom answer" button (unless allow_custom=False). This lets you:
Click a button for quick selection
OR type your own custom response
Example:
You'll see 4 buttons:
PostgreSQL
MongoDB
MySQL
โ๏ธ Custom answer (type below)
Best Practices
Use Non-Blocking Mode (
Questions require code review or deep analysis
You might be away from your device
The decision requires research or consultation
You need more than 2 minutes to respond
Use Blocking Mode (
Questions are simple yes/no decisions
You're actively working with the AI
Quick responses are expected
Using button options for multiple choice
Use Notifications (
Progress updates during long-running tasks
Task completion notifications
Error or warning alerts
Status updates that don't require a response
Keeping yourself informed while away from the computer
Project Structure
Troubleshooting
"Command 'python' not found"
Solution: Use python3 instead, or install the symlink:
The run.sh script already uses the correct Python from the virtual environment.
"Error: Could not find a Telegram Chat ID"
Solution: Make sure you've sent /start to your bot at least once.
"Permission denied: ./run.sh"
Solution: Make the script executable:
"Timeout: User did not respond in time"
Solutions:
Respond faster (within 2 minutes)
Increase timeout in the
ask_human()callUse non-blocking mode (
wait=False) for complex questions
MCP Server Not Showing in Client
Solutions:
Check the MCP settings file path is correct
Verify the absolute path in your configuration
Restart your MCP client completely
Check client logs for connection errors
Docker Container Won't Start
Check logs:
Environment Variables Not Loading
Ensure .env file exists and is properly formatted:
Permission Issues with Docker
If you encounter permission issues, ensure the .env file is readable:
Advanced Configuration
Changing the Default Timeout
You can customize the timeout per question:
Restricting to Specific User
The server uses TELEGRAM_USER_ID from .env. Only messages from this user ID will be accepted.
Using Multiple Bots
Create separate directories with different .env files and register each as a different MCP server:
Security Best Practices
โ Never commit - Already in
.gitignoreโ Use - Prevents unauthorized users from controlling your AI
โ Regenerate tokens if accidentally exposed
โ Use private Telegram bots - Don't share your bot with others
โ Use Docker secrets for sensitive data in production
โ Regularly update the base Python image for security patches
Production Deployment
For production deployment:
Remove development volume mounts from
docker-compose.ymlUse environment variables or secrets management instead of
.envfileConsider using a process manager or orchestration tool (Kubernetes, Docker Swarm)
Set up proper logging and monitoring
Configure restart policies appropriately
Example production docker-compose.yml:
Dependencies
fastmcp (2.14.2+) - MCP server framework
httpx (0.28.1+) - Async HTTP client for Telegram API
python-dotenv (1.2.1+) - Environment variable management
See requirements.txt for full list.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - Use freely!
Support
For issues with:
MCP Protocol: Check Model Context Protocol docs
FastMCP: Visit FastMCP documentation
Telegram Bot API: See Telegram Bot API docs
Changelog
v1.0.0 (2026-01-02)
Initial release
Support for blocking and non-blocking question modes
Button support for multiple choice questions
Progress notification system
Docker support
Comprehensive documentation