telegram-mcp
- Type
- MCP server
- Scanned
- Nov 13, 2026
- Version
- 6b3bd9512736
- Files read
- 165
This MCP server connects AI coding agents to your personal Telegram account via Telethon, providing over 80 tools to read and search chats, send or delete messages, manage groups and contacts, transfer media, and transcribe voice notes. Because write tools are enabled by default and coding agents automatically expose the open project folder via MCP roots, a prompt injection inside an incoming Telegram message can trick the agent into exfiltrating local workspace secrets to an attacker or modifying and deleting your Telegram chats.
What it can reach
- Secrets
- Reads Telegram API credentials, full-account Telegram session strings or SQLite session files, optional proxy credentials, and optional Groq or OpenAI transcription API keys from environment variables and the local .env file.
- Network
- Connects to Telegram MTProto servers (optionally via a configured proxy), optionally sends voice audio to Groq or an OpenAI-compatible transcription endpoint or downloads Whisper models, and can listen on an HTTP or SSE port when MCP_TRANSPORT is set to http or sse.
- Files
- Reads and writes local session files, transcript caches, contact aliases, incoming event feeds, audit/error logs, and /tmp lock files, and can read or write arbitrary files inside MCP client workspace roots or configured TELEGRAM_ALLOWED_ROOTS folders.
- Other
- Controls the authenticated personal Telegram account, including reading chats and contacts, sending, editing, forwarding, and deleting messages, creating or leaving groups and channels, changing admin/ban/privacy settings, and clicking bot callback buttons.
Findings
-
HighClient workspace roots automatically enable file tools and override TELEGRAM_ALLOWED_ROOTS
Although the documentation states that file tools are disabled by default until allowed roots are configured, coding agents such as Cursor, Claude Code, and VS Code automatically advertise the active project workspace via MCP roots/list. Unless TELEGRAM_SERVER_ROOTS_ONLY=1 is set, those client workspace roots enable send_file, upload_file (both with no file-extension filter), and download_media across the user's open project—and even replace an isolated folder explicitly configured in TELEGRAM_ALLOWED_ROOTS or manifest.json. A prompt injection in a Telegram message can therefore trick the agent into sending project secrets such as .env files to an attacker's chat.
Fix: Require an explicit opt-in before trusting client MCP workspace roots for Telegram file transfers, intersect client roots with SERVER_ALLOWED_ROOTS whenever SERVER_ALLOWED_ROOTS is configured, set TELEGRAM_SERVER_ROOTS_ONLY=1 in manifest.json when allowed_root is used, and block sensitive dotfiles like .env by default.
-
Mediuminspect_document downloads unbounded attachments into RAM and skips sanitization
telegram_mcp/tools/media.py:1299
Unlike download_media (which enforces a 200 MB cap), inspect_document downloads an entire attachment from Telegram into memory with no size check or progress cutoff, then parses all PDF pages or decodes text files without passing the filename or extracted text through sanitize_user_content(). If an agent inspects a multi-gigabyte text or PDF file sent by a stranger, the server can crash from memory exhaustion, and invisible control or bidirectional override characters inside documents bypass the server's prompt-injection sanitization.
Fix: Check declared media size and enforce a streaming progress limit (for example 10-20 MB) before buffering in inspect_document, cap PDF page counts, and pass filenames and extracted text through sanitize_name() and sanitize_user_content().
-
LowRead-only photo and emoji preview tools can overwrite files on disk
telegram_mcp/tools/media.py:1146
Both open_photo and preview_custom_emoji are annotated with readOnlyHint=True, which keeps them exposed when TELEGRAM_EXPOSED_TOOLS=read-only is set and signals MCP clients that calls can be auto-approved without user confirmation. Despite being marked read-only, both accept a save_path parameter that writes downloaded bytes directly to disk, and open_photo is missing from EXTENSION_ALLOWLISTS and MAX_FILE_BYTES, allowing a prompt-injected agent to overwrite existing files of any extension inside an allowed root.
Fix: Remove save_path from open_photo and preview_custom_emoji (leaving disk writes to dedicated non-read-only tools) or set readOnlyHint=False, and add open_photo to _DEFAULT_EXTENSION_ALLOWLISTS and MAX_FILE_BYTES with download size enforcement.
-
LowContact export and profile lookup tools bypass chat allowlist and blocklist policies
telegram_mcp/tools/contacts.py:675
When a user sets TELEGRAM_ALLOWED_CHAT_IDS or TELEGRAM_BLOCKED_CHAT_IDS to hide private conversations and contacts from the AI agent, list_contacts and search_contacts filter out restricted users, but export_contacts dumps the entire Telegram address book—including names, usernames, user IDs, and phone numbers—without checking either policy. Likewise, list_contact_aliases, get_blocked_users, get_full_user, get_user_status, get_user_photos, and get_bot_info omit allowlist and blocklist checks, letting a prompt-injected agent read restricted contact data and user profiles.
Fix: Filter export_contacts, get_blocked_users, and list_contact_aliases through is_chat_allowed, and enforce check_chat_access on resolved entities in get_full_user, get_user_status, get_user_photos, and get_bot_info.
-
LowHTTP and SSE transports have no authentication for local processes or reverse proxies
When MCP_TRANSPORT is set to http or sse (including the bundled Docker Compose configuration), the server validates Host and browser Origin headers against browser attacks, but implements no password or bearer token check. Any local user or process on a shared host can invoke tools over http://127.0.0.1:8765/mcp by omitting the Origin header, and if an operator follows the README's reverse-proxy instructions (MCP_ALLOWED_HOSTS and TELEGRAM_MEDIA_BASE_URL) without adding authentication at the proxy, anyone on the network can send non-browser requests with a matching Host header to take full control of the Telegram account.
Fix: Add built-in bearer token authentication (such as MCP_AUTH_TOKEN) for HTTP and SSE transports, and refuse non-loopback bindings or custom MCP_ALLOWED_HOSTS unless authentication is configured or explicitly bypassed.
-
LowPredictable session lock directories in /tmp lack ownership and symlink checks
Session lock files are created in fixed subdirectories of the world-writable temporary directory (/tmp/telegram-mcp-locks and /tmp/telegram-mcp-session-locks) without setting mode 0o700, verifying directory ownership, or opening lock files with O_NOFOLLOW before truncating them. On a multi-user machine, another local user can pre-create those directories to block server startup or, on systems without kernel symlink protections, plant symlinks that are truncated during lock acquisition and release.
Fix: Place session lock directories under a user-private path such as XDG_RUNTIME_DIR or ~/.local/state/telegram-mcp/locks with mode 0o700, verify directory ownership, and open lock files with os.O_NOFOLLOW.
