mcp-server-telegram
Provides integration with Telegram, allowing AI agents to send messages to staff groups or manager chats, list incoming messages from a group, and view group members via three MCP tools.
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-server-telegramSend a reminder to the staff group about the project deadline."
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-server-telegram
Model Context Protocol (MCP) server for Telegram integration. Exposes a Telegram bot as three MCP tools over the standard stdio transport.
Originally built for the YengTong 7-Scenario AI Agent demo as the second messaging channel alongside email, where:
Staff are modeled as a single Telegram group — reminders land as @mentions.
Escalations go to a separate manager-only chat, never visible to staff.
A background long-poller buffers incoming messages into a local JSON store so tool calls return synchronously with low, predictable latency.
Tools
Tool | Description |
| Send a text message to either the |
| List incoming messages buffered from the staff group. Optional |
| Setup/debug helper — list staff group members observed by the poller so far. |
Related MCP server: tgfmcp
Setup
1. Create a Telegram bot
Open Telegram and message @BotFather.
Send
/newbot, follow the prompts, and copy the bot token.Disable privacy mode for the bot (also via BotFather →
/mybots→ select your bot → Bot Settings → Group Privacy → Turn off). Without this, the bot only sees/commandmessages in groups, not regular text — the poller won't receive staff updates.
2. Create the chats
Staff group: create a Telegram group, add the bot as a member, add the 5 staff personas (or real staff).
Manager chat: a separate small group or a 1:1 DM with a manager test account that has sent
/startto the bot. This is wheretelegram_send_messagewithtarget: "manager_chat"sends to.
To obtain the chat IDs, send a message in each chat and call the Telegram API manually:
curl "https://api.telegram.org/bot<TOKEN>/getUpdates"Look for message.chat.id in the response. Group chat IDs are negative numbers (e.g. -1001234567890).
3. Configure environment
cp .env.template .env
# Edit .env with your bot token and the two chat IDs.4. Install and build
npm install
npm run build5. Run
npm startThe server boots, loads (or creates) the local store, starts the long-poller, and connects over stdio. Connect it from an MCP client.
6. Test
npm run build && node test_mcp.mjsRuns an end-to-end MCP handshake (initialize → tools/list) and verifies all three tools are registered.
Environment variables
Variable | Required | Default | Description |
| yes | — | Bot token from @BotFather |
| yes | — | Chat ID of the staff group (negative number for supergroups) |
| yes | — | Chat ID of the manager-only chat |
| no |
| Path to the local JSON message/member store |
| no |
| Delay between poll cycles (ms) — only relevant after errors |
| no |
| Seconds to hold each |
Operational notes
The poller must be running before any workflow that reads messages fires. Messages sent to the group before the poller starts are lost unless the poller's
offsetwas persisted from a previous run — on boot, the poller resumes from the last savedoffsetand Telegram redelivers any updates received while the server was down (within Telegram's 24-hour update retention window).Attachments are flagged, not fetched.
telegram_list_messagesreturnshas_attachment: truefor messages with photos/files. Photo/document captions are captured in thetextfield so the workflow still sees the sender's words. The workflow's edge-case guard routes media-bearing messages to human review; this server intentionally doesn't fetch or interpret attachment content.Consumption contract:
telegram_list_messagesdoes not mark messages as consumed. The workflow is responsible for tracking its own last-run timestamp (e.g. in the tracker CSV or a workspace key) and passing it as thesinceparameter each run. For a daily 09:00 schedule, passsince=yesterday_09:00to get the previous day's messages. Invalidsincevalues throw rather than silently returning all messages.Rate limits are handled automatically — on HTTP 429 from Telegram, the server sleeps for the
Retry-Afterduration and retries up to 3 times before surfacing the error.Graceful shutdown: SIGINT/SIGTERM aborts any in-flight long-poll immediately, stops the poller, and flushes the store to disk via an atomic temp-file-then-rename write.
Design decisions
No external Telegram library. Uses
fetchdirectly againsthttps://api.telegram.org/bot<TOKEN>/...— keeps dependencies minimal and avoids native bindings.JSON file store, not SQLite. Demo-scale volume (under a few dozen messages) doesn't justify SQLite's native dependency cost. Swap in SQLite by replacing the
loadStore/saveStoremethods if needed for larger deployments.Member list is observed, not enumerated. The Telegram Bot API has no "list all group members" endpoint.
telegram_list_group_membersreturns the set of users the poller has seen send messages into the staff group, which for a demo with seeded personas is the full set.targetis an enum, not a freeform chat ID. Constrains sends to the two pre-configured chats, so workflows can't accidentally send escalations to the wrong audience by passing a wrong chat ID.
Security notes
Bot token is a secret. Keep it in
.env, never commit it..envis in.gitignore.Sends are constrained to configured chats. The
targetenum means tool calls can only send tostaff_groupormanager_chat— the chat IDs are server-side, not caller-controlled.No attachment content is fetched or written to disk.
has_attachmentis a flag only; no risk of malicious-file write-through.
This server cannot be deployed
Maintenance
Related MCP Connectors
Telegram bridge for your MCP-compatible agent. Bidirectional, no LLM in our stack.
Unofficial Telegram MCP server — read, search, reply and react in your own Telegram account.
MCP server for Gainium — manage trading bots, deals, and balances via AI assistants
Unified inbox MCP for WhatsApp, Telegram, Email, voice — read/send messages, search, AI agents.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to send messages and interact with Telegram chats through MCP tools, with support for user management, conversation history, and bot command handling.1-
- AlicenseNot gradedqualityBmaintenanceMCP server that enables Telegram bot interaction via Telegraf, providing tools for sending, replying, reacting, editing, deleting, forwarding messages, and receiving Telegram events over an optional notification channel.29 npm3MIT
- FlicenseNot gradedqualityAmaintenanceExposes Telegram Bot API operations as MCP tools, enabling managing messages, chats, and forum topics via a FastMCP server.-
- AlicenseAqualityDmaintenanceExposes the Telegram Bot API as tools for MCP clients, enabling sending messages, photos, polls, and more via a Telegram bot.11MIT