- MCP Integration example with Telegram
MCP Integration example with Telegram
Content
MCP Integration example with Telegram
A Python-based Model Context Protocol (MCP) client and server that enables LLMs to send notifications via Telegram and receive user responses.
Features
- Send text alerts to a Telegram chat with customizable urgency levels
- Check for user replies with configurable timeouts
- Flexible template for integration with MCP-compatible LLM applications
MCP vs Function Calls or Agent tools
MCP Protocol (Model Context Protocol):
- Separates the LLM’s reasoning (the “context”) from the execution of external actions. For example, the LLM decides what action to take and the MCP server handles how to execute that action.
- This decoupling means you can update or swap out external tools without changing the core LLM model or its prompts.
- It also allows for safer and more controlled execution of actions.
LLM Function Call or Agent:
- Direct function calls or agent-based methods often mix decision-making and execution logic, which can make the system less modular.
- Changes in how an action is performed may require reengineering the agent or modifying the LLM’s prompts, making maintenance harder.
Prerequisites
- Python 3.11+
- A Telegram bot token (from @BotFather)
- Your Telegram chat ID
Installation
- Clone the repository:
git git@github.com:arananet/mcp-telegram-poc.git cd mcp-telegram-poc - Install dependencies:
pip install -r requirements.txt - Create the virtual environment:
python3 -m venv .venv - Copy
.env.exampleto.envand fill in your Telegram credentials:cp .env.example .env nano .env
Configuration
Edit .env with:
- TELEGRAM_BOT_TOKEN=your_bot_token_here
- TELEGRAM_CHAT_ID=your_chat_id_here
- OPENAI_API_KEY=your_openai_apikey
Getting a Telegram Bot Token
- Chat with @BotFather on Telegram.
- Send
/newbotand provide a name (e.g. mcp_example) and then provide an user name (e.g. mcp_example_bot) after this telegram botfather will reply with the token. - Copy the token provided.
Finding Your Chat ID
- Send a message to your bot (go to the created bot and send some example, e.g. hi).
- Visit
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates. - Find the
chatobject'sidfield. You will see something like this (e.g. "chat":{"id":107184517,"first_name":"Edu","last_name":"Arana"...) the Chat ID is 107184517.
Usage
Running Standalone
python3 src/mcp_handler.py
Programmatic Usage
For testing sending and receiving an alert:
python3 examples/test_client.py
Agent integration
For testing the integration of the MCP using an agent with autogen 0.4 framework
python3 examples/test_autogen_agent.py
Testing Locally
Use the test script (Linux/macOS):
chmod +x test_server.sh
./test_server.sh
Available Tools
send_alert
- Parameters:
message(str, required): Message to send (Markdown supported).project(str, required): Project name.urgency(str, optional): "low", "medium", "high" (default: "medium").
- Description: Sends a Telegram alert and waits for a reply.
check_reply
- Parameters:
message_id(int, required): Message ID to check.timeout_seconds(int, optional): Wait time (default: 60).
- Description: Polls for replies to a specific message.
Development
- Install dependencies:
pip install -r requirements.txt - Run server:
python3 src/mcp_handler.py - Test client:
python3 examples/test_client.py - Test Agent:
python3 examples/test_autogen_agent.py
Examples
The examples folder contains:
-
test_server.py: Runs the server standalone. -
test_client.py: Demonstrates client interaction. -
test_autogen_agent.py: Demostrates the MCP integration between an AutoGen Agent -
In the images folder you can find some screenshots of the testings.
Developer
- Eduardo Arana
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Amap Maps高德地图官方 MCP Server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
DeepChatYour AI Partner on Desktop
WindsurfThe new purpose-built IDE to harness magic
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Tavily Mcp
Playwright McpPlaywright MCP server
Serper MCP ServerA Serper MCP Server
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
ChatWiseThe second fastest AI chatbot™
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
CursorThe AI Code Editor
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.