mcp-telegram-agent
An MCP server that lets AI agents send, receive, and manage Telegram Bot messages and media interactively.
Send formatted text with inline buttons, reply keyboards, silent mode, and content protection.
Send local documents, photos, videos, audio/voice notes, and 2–10 item photo/video albums.
Create polls/quizzes, share locations and contacts, and send animated dice.
Show chat actions, edit sent text/keyboards, and delete bot messages.
Fetch pending updates or long-poll for user replies, button clicks, and poll answers.
Acknowledge callback button presses with optional text, alert, or URL.
Target the default chat or any user/group/channel via optional chat_id, with allowlist-filtered receive support.
Enables AI agents to interact with Telegram Bot API, including sending text and rich media, local files, albums, inline and reply keyboards, polls and quizzes, locations, contacts, dice, chat actions, and editing or deleting messages.
Click on "Deploy 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., "@mcp-telegram-agent send a message to my Telegram chat saying the build passed"
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.
📬 mcp-telegram-agent
Give your AI agent full Telegram Bot superpowers — zero login risk, zero setup.
A Model Context Protocol (MCP) server empowering AI agents with Telegram Bot capabilities. Built with Python (SDK-compatible with both mcp 1.x FastMCP and 2.x MCPServer), designed to work seamlessly out-of-the-box with uvx and modern AI coding agents like VS Code Cline and Claude Desktop. Also includes the ultra-short command alias tg-agent.
🔐 Stop giving AI your personal Telegram account credentials.
mcp-telegram-agent is a lightweight, zero-login-risk notification and delivery tool — just one Bot Token sends local files, reports, interactive keyboards, and rich notifications straight to your phone.
✨ Highlights
Pure Bot API Architecture — Zero login session risk, no SMS codes or sensitive credential files needed.
Dual CLI Entry Points — Call via standard
mcp-telegram-agentor the compacttg-agentalias.Full Keyboard Support — Effortlessly construct dynamic Inline Keyboards (with URLs or callback data) and custom Reply Keyboards.
Rich Media & Local Files — Deliver logs, reports, source code, images, audio, voice notes, videos, and multi-image albums (2–10 files).
Interactive Tooling — Launch quizzes, single/multiple-choice polls, GPS coordinates, digital contact cards, and animated dice.
Message Lifecycle — Broadcast bot statuses (typing, uploading) and edit or delete messages on the fly.
Interactive Receive — Pull or long-poll user replies (text messages, inline button clicks, poll answers) with
get_updates/wait_for_reply, and acknowledge button presses withanswer_callback_query.Instant uvx Execution — Run directly with no virtual environments or manual package installs.
Related MCP server: Telegram MCP Server
🚀 Quick Start
1️⃣ Create a Telegram Bot & Get the Token
Open Telegram and search for @BotFather (verified blue check).
Send
/newbotand follow the prompts: choose a display name, then a username ending inbot(e.g.my_alert_bot).BotFather replies with your Bot Token, e.g.
123456789:AAHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Keep it secret — anyone with this token can control your bot.Important: open your new bot's chat and press Start (or send
/start). A bot cannot message a user who has never started a conversation with it.
2️⃣ Get Your Personal Chat ID
Send any message (e.g. "hi") to your new bot.
Open this URL in a browser, replacing
<YOUR_BOT_TOKEN>with your token:https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdatesIn the JSON response, locate
"chat":{"id": 123456789, ...}— that number is your Chat ID.Alternative: send any message to
@userinfobotand it replies with your ID.
3️⃣ Send to Groups or Channels (Optional)
Add the bot to the group first (via group settings → Add members). For channels, the bot must be added as an administrator to post.
Group IDs are negative numbers (e.g.
-1001234567890). To find one:Temporarily add
@userinfobotto the group and forward a group message to it, orDisable the bot's Group Privacy via @BotFather (
/setprivacy→ select your bot → Disable), post a message in the group, then checkgetUpdatesas above.
Once the bot is a member of the group/channel, it can send messages there — no extra configuration needed.
4️⃣ Sending to Any Chat at Runtime
TELEGRAM_DEFAULT_CHAT_ID is only the fallback target. Every tool accepts an optional chat_id parameter, so you can simply ask your AI agent to "send this to chat ID -1001234567890":
chat_idomitted → the message goes to theTELEGRAM_DEFAULT_CHAT_IDfrom your config.chat_idprovided → the message goes to that user/group/channel instead.Requirement: the bot must be a member of that group/channel (or the target user must have pressed Start on the bot).
5️⃣ Configuration for AI Clients
Add the configuration below to your MCP settings file (e.g., cline_mcp_settings.json or claude_desktop_config.json).
✅ Recommended Configuration (All Features Enabled)
This single block enables both sending and interactive receive — just fill in your token, chat ID and allowlists:
{
"mcpServers": {
"Telegram": {
"command": "uvx",
"args": ["mcp-telegram-agent"],
"env": {
"TELEGRAM_BOT_TOKEN": "YOUR_TELEGRAM_BOT_TOKEN",
"TELEGRAM_DEFAULT_CHAT_ID": "YOUR_CHAT_ID",
"TELEGRAM_ALLOWED_CHAT_IDS": "123456789,-1001234567890",
"TELEGRAM_ALLOWED_USER_IDS": "123456789"
}
}
}
}💡 All four environment variables are optional. If one is missing, the server still starts normally — it returns a clear, human-readable error only when a tool call actually needs it. What each variable does:
TELEGRAM_BOT_TOKEN— your Bot Token; required by all sending tools.TELEGRAM_DEFAULT_CHAT_ID— the default recipient used when a tool call omitschat_id.TELEGRAM_ALLOWED_CHAT_IDS/TELEGRAM_ALLOWED_USER_IDS— interactive-receive allowlists so your agent can read back your replies (text messages, inline button clicks, poll answers); see step 6️⃣ for details. Omitting them disables receive:get_updates/wait_for_replyreturn a setup hint instead.TELEGRAM_STATE_DIR(advanced, not shown above) — directory for the persistedgetUpdatesoffset file; defaults to amcp-telegram-agentsubfolder under the system temp directory.
💡 For a credential-free trial run, omit the whole
envblock and fill in the pieces as the tool error messages instruct.
6️⃣ Interactive Receive (Allowlist) Behavior
The recommended configuration already fills in both allowlists, so get_updates / wait_for_reply can fetch or long-poll your replies. Behavior details:
TELEGRAM_ALLOWED_CHAT_IDS— comma-separated chat allowlist; when set, updates from other chats are filtered out (group IDs are negative).poll_answerevents carry nochat_id, so they cannot be matched against this list.TELEGRAM_ALLOWED_USER_IDS— comma-separated user allowlist; when set, updates are also filtered by user ID. An update passes if it hits any configured list (each unset list is simply ignored).First-call note: the very first
get_updates(no state file yet) fetches all pending updates from Telegram, and they are consumed whenmark_readistrue(the default). Usemark_read: falseto preview without consuming them.limitonly caps how many matching updates are returned per call: the offset advances only past the last returned update, so the remaining matches stay queued for the next call. Updates that don't match the allowlist ortypesare still consumed — the offset is a single stream, so a single type or chat cannot be held back.Without an allowlist,
get_updates/wait_for_replyreturn a setup hint instead of updates. Restart the MCP server after editingenv.
⚠️ Timing matters: Telegram keeps a callback query valid for only a few seconds.
get_updatesandwait_for_replyanswer button clicks automatically right when they are received (defaultauto_answer: true); only if you disable it must you callanswer_callback_queryimmediately after a click is returned — long gaps are rejected withquery is too old(a platform limit, not a bug).
🧰 Available Tools
Tool | Description |
| Send Markdown/HTML text with inline buttons or custom reply keyboards. |
| Send any local file (PDF, CSV, code, logs, archives). |
| Send image files with captions and inline buttons. |
| Send video files as native players. |
| Send music tracks or native voice audio notes. |
| Deliver 2 to 10 photos or videos as a grouped carousel. |
| Create interactive single/multiple choice polls or scored quizzes. |
| Broadcast map location points via coordinates. |
| Share phone contact cards. |
| Send animated dice, basketball, football, or slot machines. |
| Display temporary bot statuses (typing, uploading). |
| Dynamically update previously sent text and keyboards. |
| Clean up or remove specific messages. |
| Fetch pending updates once (messages, button clicks, poll answers) without waiting. |
| Long-poll until the next user reply arrives, with a timeout. |
| Acknowledge a button press to stop its loading spinner; optional alert text or URL. |
💬 Usage Examples
Once configured, simply talk to your AI agent in natural language — it picks the right tool automatically. Below are typical requests together with the tool calls the agent makes:
📢 Send a formatted notification
"Tell me in Telegram that the nightly build succeeded, with a button linking to https://example.com"
{
"tool": "send_text_message",
"arguments": {
"text": "✅ *Nightly build succeeded!*",
"parse_mode": "Markdown",
"inline_buttons": [[{"text": "Dashboard", "url": "https://example.com"}]]
}
}📁 Share local files
"Upload
logs/app.logto my Telegram and summarize the errors"
{
"tool": "send_local_document",
"arguments": {
"file_path": "logs/app.log",
"caption": "Error log summary: 3 timeout warnings"
}
}🖼️ Send an album
"Send the three screenshots in
screenshots/to my Telegram as one album"
{
"tool": "send_media_album",
"arguments": {
"file_paths": ["screenshots/1.png", "screenshots/2.png", "screenshots/3.png"],
"caption": "Latest UI screenshots"
}
}🗳️ Run a quiz in a group
"Post a quiz to chat ID -1001234567890: which port does HTTPS use? Options 80 / 443 / 8080, the answer is 443, with a short explanation"
{
"tool": "send_poll",
"arguments": {
"chat_id": "-1001234567890",
"question": "Which port does HTTPS use?",
"options": ["80", "443", "8080"],
"type": "quiz",
"correct_option_id": 1,
"explanation": "HTTPS defaults to port 443."
}
}♻️ Update or clean up messages
"Change that deployment notice to 'finished', then delete the old reminder (ID 120)"
{
"tool": "edit_message_text",
"arguments": { "message_id": 123, "text": "🚀 Deployment **finished**" }
}{
"tool": "delete_message",
"arguments": { "message_id": 120 }
}📨 Wait for a reply and confirm a button click
"Ask me a yes/no question with inline buttons, wait for my answer, and tell me what I clicked"
{
"tool": "send_text_message",
"arguments": {
"text": "Deploy to production now?",
"inline_buttons": [[{"text": "Yes", "callback_data": "deploy:yes"}, {"text": "No", "callback_data": "deploy:no"}]]
}
}{
"tool": "wait_for_reply",
"arguments": { "types": ["callback_query"], "timeout": 25 }
}{
"tool": "answer_callback_query",
"arguments": { "callback_query_id": "<callback_query.id from the click>", "text": "🚀 Deploying…" }
}💡 Requires the step 5️⃣ allowlist. Use
get_updatesfor a one-shot, non-blocking check (addmark_read: falseto peek without consuming updates) andwait_for_replyto long-poll until something arrives. Callback clicks are auto-answered the moment they are fetched; passauto_answer: falseonly when you need a custom prompt, alert, or URL viaanswer_callback_query.
💡 When
chat_idis omitted, messages go toTELEGRAM_DEFAULT_CHAT_ID; pass it explicitly to reach any user, group, or channel — see step 4️⃣ above.
🛠️ Development & Release Flow
Develop against
main— all feature work and PRs land here.Publishing happens only from the
releasebranch: open a PRmain→release, bumpversioninpyproject.tomlwithin the PR, then merge — CI builds and publishes to PyPI automatically, and creates a matching GitHub Release (v*tag + auto-generated notes).If the version was not bumped, the workflow skips publishing with a clear warning — docs-only PRs won't break CI.
Direct pushes to
releaseare blocked by branch protection; always go through a PR.
📄 License
This project is licensed under the MIT License.
Available Tools
16 toolsanswer_callback_queryA
Acknowledge a callback button press so the loading spinner on the button stops.
對使用者點擊的行內按鈕回應,關閉按鈕上的載入動畫;text 可顯示小提示。
callback_query_id 來自 get_updates / wait_for_reply 的 callback_query 事件。
url 傳入時以開啟網址取代 text 提示(須為 http/https 開頭),
並與 text 互斥(兩者不可同時傳入);cache_time 為結果快取秒數
(0-604800),預設 0。
show_alert=True 時必須帶 text,否則回傳錯誤。
注意:callback_query 只有數秒有效,get_updates / wait_for_reply 回傳後
應立刻呼叫本工具;輪詢架構下若間隔過長會收到 query is too old,
建議搭配 wait_for_reply 的長輪詢,或背景常駐輪詢並立即應答。
Inputs: callback_query_id (required), url, text, cache_time, +1 more. Returns: result
delete_messageA
Delete a specific message by ID (can only delete messages sent by the bot).
刪除指定 ID 的訊息(僅能刪除機器人自己發送的訊息)。
Inputs: message_id (required), chat_id. Returns: result
edit_message_textB
Edit the text or keyboard of a previously sent message (does not work for media albums).
編輯先前已發送的文字訊息內容或鍵盤佈局。
Inputs: text (required), message_id (required), chat_id, parse_mode, +4 more. Returns: result
get_updatesA
Fetch pending user updates (messages, button clicks, poll answers) once without waiting.
一次性拉取待處理的更新並歸一化回傳,不等待新訊息。
chat_id 未傳時使用 TELEGRAM_DEFAULT_CHAT_ID;未設定白名單時回傳設定提示。
types 可選 message、callback_query、poll_answer,預設全部。
mark_read=False 時不移動 offset,同一批訊息下次仍會回傳(預設會讀取並推進)。
auto_answer=True(預設,僅 mark_read=True 時生效)時,回傳的 callback_query
會當下立即以通用提示應答,payload 標記 auto_answered=True,消除取回後
手動應答超過有效窗口(query is too old)的競態;應答失敗時改標記
auto_answer_error,不影響更新回傳。需要自訂提示文字、show_alert 或 url
時設 auto_answer=False,改以 answer_callback_query 手動應答。
limit 只限制單次回傳筆數:offset 僅推進到實際回傳的最後一筆,
截斷的其餘符合項目會留待下次呼叫(因此其應答也延後到下一頁取回時);
無符合項時整批消耗(含白名單外與 types 以外的更新)以免積壓堆積——
offset 為單一串流,無法單獨保留某個型別或某間聊天室的更新。
注意:首次呼叫(尚無狀態檔)時 Telegram 會回傳全部未確認的 pending
updates,且 mark_read 預設 true 會將其讀取推進;若不想消耗歷史積壓,
第一次呼叫請先以 mark_read=False 預覽。
Inputs: limit, types, chat_id, mark_read, +1 more. Returns: result
send_chat_actionB
Broadcast ongoing bot status to the user (e.g., typing, uploading document, recording).
向使用者廣播機器人當前的操作狀態,如打字中、上傳檔案中等。
Inputs: action, chat_id. Returns: result
send_contactC
Send a vCard contact so the user can save it to their address book.
發送名片聯絡人,可儲存至通訊錄。
Inputs: first_name (required), phone_number (required), chat_id, last_name. Returns: result
send_diceC
Send an animated random-value emoji (dice, dart, basketball, football, bowling, slot machine).
發送擲骰子等動態隨機結果的動畫元件。
Inputs: emoji, chat_id. Returns: result
send_local_audio_or_voiceB
Send a local audio file as a music track or a native voice note (OGG/Opus recommended).
發送本機音訊檔案:mode=audio 以音樂曲目呈現(可附標題與演出者); mode=voice 以原生語音訊息呈現(建議使用 OGG/Opus 編碼)。
Inputs: file_path (required), mode, title, caption, +4 more. Returns: result
send_local_documentC
Send any local file (code, reports, logs, zip, pdf) as a general document.
傳送本機任何檔案給使用者,涵蓋程式碼、日誌、PDF 與壓縮檔等。
Inputs: file_path (required), caption, chat_id, parse_mode, +2 more. Returns: result
send_local_photoC
Send a local image file as a full-preview photo.
發送本機圖片檔案,以照片預覽格式呈現。
Inputs: photo_path (required), caption, chat_id, parse_mode, +1 more. Returns: result
send_local_videoC
Send a local video file (MP4, etc.) as a playable streaming video.
發送本機影片檔案,以內嵌播放器形式呈現,支援串流播放。
Inputs: video_path (required), width, height, caption, +4 more. Returns: result
send_locationB
Send a geographic location card that opens directly in the map app.
發送地理位置卡片,可直接開啟地圖導航。
Inputs: latitude (required), longitude (required), chat_id. Returns: result
send_media_albumC
Send 2 to 10 local photos or videos as a single grouped album (carousel).
批次發送 2 至 10 個本機圖片或影片,組合成輪播相簿。
Inputs: file_paths (required), caption, chat_id, protect_content, +1 more. Returns: result
send_pollB
Send a poll or quiz card with clickable options.
發送投票或測驗卡片,供使用者點選。type=quiz 時可指定正確選項與解析說明。
Inputs: options (required), question (required), type, chat_id, +4 more. Returns: result
send_text_messageC
Send text messages with Markdown/HTML formatting, silent mode, protection, inline buttons, or custom reply keyboards.
發送文字訊息。支援 Markdown 與 HTML 格式解析、靜音推播、內容保護、行內按鈕與底部鍵盤。
Inputs: text (required), chat_id, parse_mode, inline_buttons, +5 more. Returns: result
wait_for_replyA
Wait for the next user reply (message, button click, or poll answer) via long polling.
長輪詢等待使用者下一則回覆(訊息/按鈕點擊/投票作答)。
連續長輪詢(每段最長 10 秒)直到 timeout 秒內出現符合項目或逾時;
poll_interval 僅用於網路錯誤後的退避等待(至少 1 秒),正常情況下不會隔段輪詢。
auto_answer=True(預設)時,回傳的 callback_query 會當下立即以通用提示
應答,payload 標記 auto_answered=True,不需也切勿再用 answer_callback_query
重複應答(將收到 query is too old);應答失敗時改標記 auto_answer_error。
需要自訂提示文字、show_alert 或 url 時設 auto_answer=False。
未設定白名單時回傳設定提示,請 AI 提醒使用者補上 TELEGRAM_ALLOWED_CHAT_IDS 後重啟。
注意:
- 首次呼叫(尚無狀態檔)時會先撈回全部 pending updates,最舊的先被
比對回傳;建議先以 get_updates(mark_read=False) 預覽確認沒有積壓。
- types 以外的更新仍會被讀取推進(offset 單一串流,無法單獨保留);
若等待訊息期間按鈕被點擊,該 callback_query 會被消耗而不回傳,
需要接收點擊事件時請讓 types 涵蓋 callback_query。
Inputs: types, chat_id, timeout, auto_answer, +1 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 16 tools
Each send_* tool targets a distinct Telegram media type (video, document, photo, audio/voice, album, poll, location, contact, dice), so selection is mostly unambiguous; the one soft boundary is photo vs document for image files, which the descriptions partially clarify. The polling pair is also well separated: get_updates is explicitly one-shot/non-blocking while wait_for_reply is long-polling, and the descriptions spell out when to use each.
Names follow a clear snake_case verb_noun convention (send_*, get_updates, answer_callback_query, edit_message_text, delete_message), which is easy to scan and predict. Minor deviation: four tools insert a 'local' infix (send_local_video/photo/document/audio_or_voice) while send_media_album, send_poll, send_location do not, and send_local_audio_or_voice is an outlier in length.
16 tools is at the upper end but justified: Telegram genuinely has many distinct message payload types, each needing its own tool because they take different parameters. Nothing looks like filler, though a few rarely used ones (send_dice, send_contact) inflate the surface slightly.
The outbound surface is broad and lifecycle actions (edit_message_text, delete_message) plus inbound (get_updates, wait_for_reply, answer_callback_query) are covered, so core workflows work. Gaps remain: no forward_message or copy_message, no sending media from a URL/file_id (only local files), and no caption/album editing or chat-info lookup, which will block some common bot flows.
Maintenance
Related MCP Connectors
Let AI assistants post to your Telegram chats, groups and channels. Not affiliated with Telegram.
WhatsApp and Telegram for AI agents, behind a policy gateway. OAuth or access key.
Multi-tenant Telegram gateway for AI agents — HTTP+stdio, 8 tools, MTProto User API
Email, WhatsApp and Telegram for AI agents: send, campaigns, automations, contacts, agent inboxes.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI agents to send and receive messages, media, and files on Telegram, and manage chats via a bot token.1755 PyPIMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with the Telegram Bot API, allowing them to send messages, forward messages, get bot information, and receive updates.3MIT
- AlicenseBqualityDmaintenanceEnables AI agents to send notifications and media (text, photos, documents, videos) via a Telegram bot.4138 npm4Do What The F*ck You Want To Public
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to interact with Telegram through 50+ tools for chats, messages, contacts, users, groups, and channels, with per-topic isolation and a reactive inbox for multi-agent use.MIT