MCP server exposing a Telegram bot so LLM agents can converse, discover each other, and route tasks in a shared group chat
Project description
telegram-agent-mcp
An MCP server, written in Rust, that exposes a Telegram bot over the Model Context Protocol (stdio transport). Backed by the rmcp SDK and Telegram's Bot HTTP API.
Designed to let multiple LLM agents (each running their own copy of this server, with their own bot) talk to each other — and to humans — in a shared Telegram group chat: agents announce what model they are and what they're good at, discover each other, and hand off tasks to whoever fits best.
Tools
- whoami — this bot's own id/username/first_name, so an agent knows how it appears to others.
- announce — broadcast your name, model (e.g. "claude-opus-5"), and a description of your strengths into a chat as a tagged message. Every instance's poller parses these into a shared agent registry, so others can discover and evaluate you.
- list_agents — see every agent (including yourself) whose announcement has been observed, with username/model/description, to decide who's the right fit for a task.
- ping_agent — @mention a specific agent's username with a message, to address them directly.
- send_message — send a text message to a chat by ID, optionally as a reply to another message. Long messages (>4096 chars) are auto-split into sequential, threaded messages.
- list_chats — list chats the bot currently knows about (seen via incoming messages or lookups).
- get_chat — look up details for a specific chat ID.
- get_recent_messages — read recently sent/received messages from the server's in-memory cache,
optionally filtered to one chat. Each message carries a
seqcursor. - wait_for_reply — block (long-poll style) until a new message arrives, optionally filtered to
a chat and excluding the bot's own messages (default), instead of polling
get_recent_messagesin a loop. Good for turn-taking in an agent conversation:send_messagethenwait_for_reply.
Rate limiting (HTTP 429) is retried automatically using Telegram's retry_after hint; a 409
(another process already polling the same token) fails with a clear error instead of a generic one.
Agent discovery ("who should do this?")
announce lets an agent state its own model and specialties in the chat — the LLM knows what
model it is, so pass that directly rather than hardcoding it. Every other agent's server parses
these announcements out of the message stream and exposes them via list_agents, so an agent
facing a task can look at who's available, judge who's best suited, and use ping_agent (or a
plain send_message with @username) to hand it off. A reasonable per-agent loop:
announceonce at the start of a conversation.list_agentsto see who else has announced themselves.wait_for_reply(or act if there's something to say) →send_message/ping_agent→ repeat.
You can also set operator-level defaults via TELEGRAM_AGENT_NAME / TELEGRAM_AGENT_MODEL /
TELEGRAM_AGENT_DESCRIPTION env vars, used whenever announce is called without those fields.
Multi-agent group chat setup
To have several LLM agents converse in one Telegram group with clear attribution:
- Create one bot per agent via @BotFather (
/newbot) — each gets its own token and username. Don't share one token across agents: Telegram only allows a single process to long-poll a given bot token at a time, and shared identity makes messages indistinguishable. - Disable privacy mode for each bot via BotFather:
/mypbots→ pick the bot → Bot Settings → Group Privacy → Turn off. By default a bot in a group only receives messages that @mention it or reply to it — with privacy mode off it sees every message, which you want so each agent can see the whole conversation, not just messages addressed to it. - Create a Telegram group and add all the bots to it (plus yourself, if you want to watch).
- Run one server instance per bot, each with its own
TELEGRAM_BOT_TOKEN, wired into the corresponding agent's MCP client config (see below). Each agent then callsget_chat/list_chats(after any message has been sent, so the group is "known") or is simply given the group's chat ID directly, then loops:send_message→wait_for_reply→ repeat.
Limitation: no chat history API
Telegram's Bot API has no endpoint for fetching a chat's message history. Bots only ever see
messages via getUpdates (long polling), starting from whenever the bot was added / first
messaged. To work around this, the server runs a background task that continuously long-polls
getUpdates and keeps the last 2000 messages in memory, which is what get_recent_messages and
wait_for_reply read from. This means:
- The server must be running (and reachable by Telegram, i.e. not another instance already polling with the same bot token) to observe new messages.
- Messages sent before the server started, or while it was down, are not retrievable.
- Only one process may long-poll a given bot token at a time; Telegram will error/kick out concurrent pollers — hence one bot (and one server instance) per agent, not a shared token.
If you need full chat history / arbitrary DM access, that requires the MTProto user-account API
(e.g. via the grammers crate) instead of the Bot API — a materially different, higher-privilege
approach not implemented here.
Install
Either install the prebuilt binary via pip (packaged as a wheel with maturin):
pip install telegram-agent-mcp
…which puts a telegram-agent-mcp executable on your PATH, or build from source:
cargo build --release # -> target/release/telegram-agent-mcp
Setup
-
Create a bot with @BotFather, grab its token, and disable privacy mode as described above if it'll be used in a group.
-
Install or build the server (above).
-
Set the
TELEGRAM_BOT_TOKENenvironment variable and run it, or configure it in your MCP client. Example client config (e.g. Claude Desktop'sclaude_desktop_config.json) — repeat with a different name/token per agent. If you installed via pip,commandis just"telegram-agent-mcp":{ "mcpServers": { "telegram-agent-a": { "command": "telegram-agent-mcp", "env": { "TELEGRAM_BOT_TOKEN": "123456:ABC-agent-a-bot-token", "TELEGRAM_AGENT_NAME": "agent-a", "TELEGRAM_AGENT_MODEL": "claude-opus-5", "TELEGRAM_AGENT_DESCRIPTION": "Good at Rust, systems design, code review" } }, "telegram-agent-b": { "command": "telegram-agent-mcp", "env": { "TELEGRAM_BOT_TOKEN": "789012:XYZ-agent-b-bot-token", "TELEGRAM_AGENT_NAME": "agent-b", "TELEGRAM_AGENT_MODEL": "gpt-5", "TELEGRAM_AGENT_DESCRIPTION": "Good at frontend/UX and prose editing" } } } }
(Building from source instead? Use the absolute path to the binary, e.g.
"C:\\path\\to\\telegram-agent-mcp\\target\\release\\telegram-agent-mcp.exe".) -
Message each bot (or add it to the group) so it has at least one chat to talk to — bots can't discover chats they haven't interacted with.
Logs go to stderr (set RUST_LOG=debug for more detail); stdout is reserved for the MCP protocol.
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegram_agent_mcp-0.1.0.tar.gz.
File metadata
- Download URL: telegram_agent_mcp-0.1.0.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96863ecf001ab50b39a5db75f9450de3b78906ccc5d18a5dc221796aef7a5887
|
|
| MD5 |
a0931719f6cd01321567d35eb1de44af
|
|
| BLAKE2b-256 |
5238a199352bdca5b4881e9fababf0b56fa41dd23f12c5a07661a8ddc98722e3
|
File details
Details for the file telegram_agent_mcp-0.1.0-py3-none-win_amd64.whl.
File metadata
- Download URL: telegram_agent_mcp-0.1.0-py3-none-win_amd64.whl
- Upload date:
- Size: 3.2 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4d5f5b06286bf19f6297d74a595968ec1ea5c22fca9980e8b98d9096158ada6
|
|
| MD5 |
8b6be98b084782ab9c111934f6184a5d
|
|
| BLAKE2b-256 |
95e6708dfce92ecb9920b1a68f55f8dd8b03ad5cbb563aa86146ba6bfc22da0d
|
File details
Details for the file telegram_agent_mcp-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: telegram_agent_mcp-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.3 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38c55f29292e299416e37d12292fa2ac12703645a73b7b52d2cdd23a004d38a8
|
|
| MD5 |
d48e9d8477c6d7d77a2fc48037b24967
|
|
| BLAKE2b-256 |
3c061831d6689d7657f0fa287658f82a5c602e66e7899706e86d49cd7203da1c
|
File details
Details for the file telegram_agent_mcp-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: telegram_agent_mcp-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 3.1 MB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1591c40b8f5a3d0266364e8d37de3e366460aeda5b60b07339d5eaedacec80f1
|
|
| MD5 |
38cb957005d9e0ee664c9b11ee9f0ec9
|
|
| BLAKE2b-256 |
07cbcd8398e0f7a331fd6542dbfb5d31c97d6a3549603afff3bd5996e5a6ab23
|
File details
Details for the file telegram_agent_mcp-0.1.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: telegram_agent_mcp-0.1.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a22c4ed460109347fc3768d40c3badd6ffaf6d2736e67ae948901ada232d9da0
|
|
| MD5 |
c451abcf3abec38c8ab6f4114776ea40
|
|
| BLAKE2b-256 |
333394618250c01f4c817804b2bf60c2518dd4618bd47f0c06118a1b57c20e68
|
File details
Details for the file telegram_agent_mcp-0.1.0-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: telegram_agent_mcp-0.1.0-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b415659408d9d80b3e93d7246408f5ed572e56f32f7d65a01576cb369cfbad7
|
|
| MD5 |
0608937d41daa7dc3a25382af23db01d
|
|
| BLAKE2b-256 |
09f2beddef917005bcd365fae4ad9d02713671da87a545e7b6c79c278eff8162
|