MCP Integration example with Telegram
LocalAbout MCP Integration example with Telegram
A Python MCP server and client example that lets LLM applications send Telegram alerts and collect replies. It provides separate tools for sending alerts and checking responses, with urgency and timeout options.
Key features
- 01Send Telegram text alerts
- 02Set alert urgency
- 03Check replies with a timeout
- 04Example integration with MCP applications
Use cases
- 01Notify a Telegram chat about project events
- 02Collect a response to an alert
- 03Test MCP integration with an agent
MCP support
The MCP server exposes `send_alert` and `check_reply` tools to MCP clients. The repository also includes a client example for testing interactions.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP 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 [email protected]: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
Availability
- Certified by MCPHub https://mcphub.com/mcp-servers/arananet/mcp-telegram-poc
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.