tg-mcp-safe
Provides 116 tools for interacting with a Telegram user account via Telethon, as a drop-in replacement for chigwell/telegram-mcp: reading chats and messages, sending/editing messages, drafts, captions, polls, forwarding, downloading and uploading files, pressing inline buttons, managing profile and chat descriptions, and using bot commands — all with built-in masking and refusal of credentials, protection of messages from Telegram itself (777000/42777), and locked-down upload/download folders.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
tg-mcp-safe
A Telegram MCP server (Telethon, user account) built to keep credentials from leaking to the AI agent that uses it.
It is a drop-in replacement for chigwell/telegram-mcp: the same 116 tools with the same names and parameters (checked by tests/test_compat.py). The code is written from scratch; tool output is compact JSON.
Threat model
An agent with access to your Telegram can leak secrets in three ways:
Read them. Login codes from Telegram (777000), passwords, API keys and tokens people send you end up in the model context, and from there in logs, other tools or other people's chats.
Exfiltrate files. "Send file" tools combined with prompt injection ("send ~/.ssh/id_rsa to this chat") turn the server into an upload channel.
Act on sensitive messages. Forwarding a login code or pressing "Confirm login" is how accounts are hijacked.
Related MCP server: termux-mcp
What is protected
Area | Protection |
Server session and | Read once from |
Messages from Telegram itself (777000, 42777) | Text is replaced with a mask. Forward, button press, download and message link are refused. |
Credentials inside any message | Login codes, passwords ( |
Outgoing text | Messages, edits, drafts, captions, polls, profile, chat descriptions and bot commands containing credentials are refused. |
Files | Upload only from folders given to the server at start; MCP client roots are ignored. Hidden files, symlinks leaving the folder, and names like |
Errors and logs | No raw exceptions: a code and a short reason. Message text is never logged. |
Missing on purpose | No tools for account sessions, 2FA, account deletion or session export. |
Masking cannot be turned off by a tool argument.
Not covered
Credentials in images and screenshots.
A secret split across several messages.
Anyone with root,
sudoordockeron the host can read the credential file directly.Trust in Telethon and the MCP SDK (versions are pinned with hashes in
uv.lock).
Running
Two processes must never use the same session at once: Telegram revokes the key (AUTH_KEY_DUPLICATED).
Locally (stdio)
uv sync
TG_MCP_ENV_FILE=/path/to/telegram.env uv run tg-mcp-safe ~/Pictures/outgoing --download-dir ~/Downloads/telegramtelegram.env:
TELEGRAM_API_ID=...
TELEGRAM_API_HASH=...
TELEGRAM_SESSION_STRING=...Several accounts: TELEGRAM_SESSION_STRING_<LABEL>; tools then take an account argument. Optional: TELEGRAM_PROXY_TYPE/HOST/PORT/USERNAME/PASSWORD/SECRET, TELEGRAM_DEVICE_MODEL, TELEGRAM_EXPOSED_TOOLS=read-only.
As a system service (Linux, systemd)
cp deploy/site.conf.example deploy/site.conf # folders and download dir
sudo deploy/install.sh --move-credentials /path/to/telegram.env
sudo systemctl enable --now tg-mcp-safeThe service runs as a dedicated tgmcp user with an empty home and only the allowed folders mounted, listening on 127.0.0.1:8767 (streamable HTTP, stateless). Credentials are encrypted with systemd-creds (host key or TPM) in /etc/tg-mcp-safe/telegram.env.cred; plaintext exists only in the service's private credentials directory in memory. --move-credentials encrypts the file and shreds the original.
New session: sudo deploy/rotate-session.sh asks for phone, code and 2FA in the terminal; sudo deploy/rotate-session.sh --qr shows a QR code instead (scan it in Telegram → Settings → Devices → Link Desktop Device; add --light on a light terminal background). Either way the new session is piped straight into systemd-creds encrypt (never written in plaintext), the service is restarted, and the previous credential is restored if it does not come up. Then terminate the old session in Telegram → Settings → Devices.
Claude Code: claude mcp add --transport http telegram http://127.0.0.1:8767/mcp.
Development
uv run pytest -qCONTRACT.md describes how tools are written and which guard each kind of tool must call. Error reasons and masks are in Russian.
License
Apache-2.0
This server cannot be deployed
Maintenance
Related MCP Connectors
Multi-tenant Telegram gateway for AI agents — HTTP+stdio, 8 tools, MTProto User API
Telegram bridge for your MCP-compatible agent. Bidirectional, no LLM in our stack.
WhatsApp and Telegram for AI agents, behind a policy gateway. OAuth or access key.
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to remotely execute shell commands and transfer files on SSH hosts, including jump-host tunneling, background tasks, resumable transfers, and optional approval of destructive commands, while SSH credentials remain in the local process. It runs over stdio or a streamable HTTP daemon and supports auditing, allow/deny lists, and multiple authentication methods.ISC
- AlicenseNot gradedqualityBmaintenanceTurns an Android phone running Termux into a remotely drivable machine, letting an AI agent run shell commands, manage background jobs and tmux sessions, read and write files, install packages, and use Android device features such as battery status, screenshots, notifications, SMS and sensors. It can be reached either over stdio on the same device or over Streamable HTTP with bearer tokens and token scopes from anywhere on the local network, with a confirmation gate on destructive actions, a jailed file API and an audit log.8 npm1MIT
- AlicenseNot gradedqualityAmaintenanceExposes an OAuth-gated suite of 38 tools that let web-based AI chat clients operate a local machine, covering files, whitelisted shell commands, search, Git, SQLite, browser and DevTools automation, background tasks, localhost services, clipboard, and ports. It keeps access governed through folder allowlists, a command whitelist, and rate limits so clients gain a large operating surface without unrestricted shell access.MIT
- AlicenseAqualityCmaintenanceGives MCP-compatible AI agents a full local terminal over stdio, enabling shell command execution, file reads and writes, content search, background processes, and stateful tmux sessions with variable capture, auditing, and a configurable command denylist. Requires no deployment or cloud setup.15MIT