MCP server for Telegram Client API (MTProto)
MCP server for Telegram Client API (MTProto). Provides 58 tools, 4 resources, 3 prompts, and argument completions for comprehensive Telegram account management.
Uses gotd/td for MTProto protocol — this is a user account client, not a bot.
| Feature | Status |
|---|---|
| Tools | 58 tools with annotations (read-only / idempotent / write / destructive) |
| Resources | 4 (dialogs, profile, chat info, chat messages) |
| Prompts | 3 (reply, summarize, search and reply) |
| Completions | Peer argument autocompletion from dialogs |
| Elicitation | Auth flow (phone, code, 2FA password) |
| Progress | File uploads, media albums, message search |
| Roots | File path validation for uploads/downloads |
| Transports | stdio + HTTP/SSE |
| KeepAlive | 30s ping interval |
| Middleware | Auth guard, request logging |
t.me/+hash and t.me/joinchat/hash are resolved via messages.checkChatInviteoffsetDate for dialog listing, offsetId for message search and historytg_messages_list — List messages in a chattg_messages_get — Get specific messages by IDtg_messages_context — Get messages around a specific messagetg_messages_search — Search messages in a chattg_messages_send — Send a text messagetg_messages_edit — Edit an existing messagetg_messages_delete — Delete messagestg_messages_forward — Forward messages between chatstg_messages_pin — Pin or unpin a messagetg_messages_react — Add or remove reactionstg_messages_mark_read — Mark messages as readtg_dialogs_list — List all dialogstg_dialogs_search — Search dialogs by querytg_dialogs_get_info — Get chat/channel metadatatg_contacts_get — Get contact infotg_contacts_search — Search contactstg_users_get — Get user infotg_users_get_photos — Get user profile photostg_users_block — Block or unblock a usertg_users_get_common_chats — Get chats shared with a usertg_groups_list — List groupstg_groups_info — Get group infotg_groups_join — Join a public channel or supergrouptg_groups_leave — Leave a group or channeltg_groups_rename — Rename a grouptg_groups_members_add — Add a membertg_groups_members_remove — Remove a membertg_groups_invite_link_get — Get invite linktg_groups_invite_link_revoke — Revoke invite linktg_chats_create — Create a new group or channeltg_chats_archive — Archive or unarchive a chattg_chats_mute — Mute or unmute notificationstg_chats_delete — Delete a channel or supergrouptg_chats_set_photo — Set chat phototg_chats_set_description — Set chat descriptiontg_chats_get_admins — List administrators (channels/supergroups)tg_chats_set_permissions — Set default permissionstg_messages_send_file — Send a file with captiontg_media_download — Download media from a messagetg_media_upload — Upload a filetg_media_send_album — Send a media albumtg_profile_get — Get own profile infotg_profile_set_name — Update display nametg_profile_set_bio — Update biotg_profile_set_photo — Set profile phototg_topics_list — List forum topicstg_topics_search — Search forum topicstg_stickers_search — Search sticker setstg_stickers_get_set — Get a sticker settg_stickers_send — Send a stickertg_drafts_set — Set a draft messagetg_drafts_clear — Clear a drafttg_folders_list — List chat folderstg_folders_create — Create a foldertg_folders_edit — Edit a foldertg_folders_delete — Delete a foldertg_typing_send — Send typing indicatortg_online_status_set — Set online/offline statustg://dialogs — List of all dialogs (JSON)tg://profile — Authenticated user's profile (JSON)tg://chat/{peer} — Chat/channel metadata (JSON, URI template)tg://chat/{peer}/messages — Recent messages (text, URI template)reply_to_message — Fetch context around a message for composing repliessummarize_chat — Fetch recent messages for conversation summarizationsearch_and_reply — Search messages and prepare reply contextAll tools accept peer as a string. Supported formats:
@usernameusername (bare)https://t.me/usernamehttps://t.me/+invite_hash (invite links, if already joined)-100xxx=channel)Peers resolved by username include a valid access hash. Numeric IDs use a cached access hash if available, otherwise AccessHash=0 (some API calls may fail — prefer @username).
| Variable | Description | Default | Required |
|---|---|---|---|
TELEGRAM_APP_ID | API app_id from my.telegram.org | — | Yes |
TELEGRAM_APP_HASH | API app_hash from my.telegram.org | — | Yes |
TELEGRAM_PHONE | Phone number (E.164 format) | — | No (prompted via elicitation) |
TELEGRAM_PASSWORD | 2FA password | — | No (prompted via elicitation) |
TELEGRAM_SESSION_FILE | Session file path | ~/.mcp-tg/session.json | No |
TELEGRAM_AUTH_CODE | One-time auth code | — | No (prompted via elicitation) |
TELEGRAM_DOWNLOAD_DIR | Media download directory | /tmp/mcp-tg/downloads | No |
MCP_HTTP_PORT | HTTP/SSE transport port | disabled | No |
MCP_HTTP_HOST | HTTP bind address | 127.0.0.1 | No |
Authentication uses a cascade: environment variable, then MCP elicitation (the client prompts you), then error.
First run:
TELEGRAM_APP_ID and TELEGRAM_APP_HASH (always required)TELEGRAM_PHONE — if not set, the server asks via elicitationTELEGRAM_AUTH_CODE — if not set, the server asks via elicitationTELEGRAM_PASSWORD — or the server asksTELEGRAM_SESSION_FILESubsequent runs: session file is loaded automatically, no auth needed.
Session persistence in containers: mount a volume for the session file:
-v ~/.mcp-tg:/home/nobody/.mcp-tgMultiple sessions: each Claude Code session starts its own container. This is safe for normal use — Telegram allows multiple MTProto connections with the same auth key. However, avoid running many instances simultaneously (5+), as Telegram may rate-limit or drop connections. Session file writes are rare (only on re-auth or DC migration) so volume sharing is safe in practice.
claude mcp add mcp-tg -- docker run --rm -i \
-e TELEGRAM_APP_ID \
-e TELEGRAM_APP_HASH \
-v ~/.mcp-tg:/home/nobody/.mcp-tg \
ghcr.io/lexfrei/mcp-tg:latestexport TELEGRAM_APP_ID=12345
export TELEGRAM_APP_HASH=your_app_hash
./mcp-tgdocker run --rm -i \
-e TELEGRAM_APP_ID=12345 \
-e TELEGRAM_APP_HASH=your_app_hash \
-v ~/.mcp-tg:/home/nobody/.mcp-tg \
ghcr.io/lexfrei/mcp-tg:latestgo build ./cmd/mcp-tgdocker build --file Containerfile --tag mcp-tg .BSD 3-Clause License
lexfrei/mcp-tg
April 2, 2026
April 13, 2026
Go