Telegram MCP server in Rust, safe to run on your real account
One self-hosted Rust binary connecting Claude, Codex, Antigravity, or any MCP client to one or multiple personal Telegram accounts over MTProto. 68 tools, an embedded /settings web panel, built-in OAuth 2.1, and deterministic Rust guardrails so a prompt-injected model cannot wreck your account.
What your agent can do in Telegram
| Capability | Included out of the box |
|---|---|
| Reading, search & media | Dialogs, global search, photos and images passed directly to the model (ImageContent in RAM), voice transcription (Premium), translation, polls, stories, boosts, and forum topics. |
| Messaging & cloud drafts | Send, edit, forward, schedule, Markdown/HTML formatting, reactions, stickers, inline bot queries, and Telegram cloud drafts (the agent drafts a reply, you review and press Send). |
| Organization & full MTProto | Chat folders, archive, mute, pin, unread markers, contacts, group moderation, profile/privacy, active sessions, Telegram Business, and Stars (higher-risk tiers stay locked until you allow them). |
| Context control & prompts | 6 presets from core (15 tools) to full (68) with live prompt-token estimates, 4 built-in MCP prompts (unread_triage, chat_digest, draft_reply, search_brief), and telegram:// resources. |
| Multi-account in one binary | Run personal and work accounts side by side with isolated session_<alias>.db files, policies, and limits via unpinned /mcp or pinned /mcp/<alias> endpoints. |
| Local & remote MCP | stdio for local clients (Claude Code, Codex, Antigravity); Streamable HTTP with bearer auth or built-in OAuth 2.1 (PKCE, DCR, refresh rotation) for remote connectors like Claude.ai on web and mobile. |
See the full breakdown of all 68 tools, presets, prompts, and resources or compare gramcp with other Telegram MCP servers.
Embedded /settings web panel & multi-account
In HTTP mode, gramcp serves a React/TypeScript management panel compiled directly into the Rust binary via rust-embed (English and Russian). Six views cover day-to-day control with an account switcher on every tab: Tools (per-tool toggles, presets, and live prompt-token estimates), Chats (send whitelist with @username → ID pinning and read blacklist), Policy (instant kill switch that also cancels scheduled Telegram sends, plus outgoing signature editor), Accounts (add or re-authorize Telegram accounts live by QR code + 2FA without restarting), OAuth (client inspection and revocation), and Audit.
/settings returns 404 until you configure Argon2id password login, Cloudflare Access RS256 JWT verification, or loopback trusted-proxy auth, and refuses any MCP or OAuth token with 403. See multi-account setup and all six panel views.
Built to survive prompt injection
Connecting an LLM to a real Telegram account means anyone who can message you can put instructions into your agent's context. If a group message tells the model to forward 50 messages from “Family” to @totally_legit_backup and delete the evidence, gramcp enforces policy in Rust before any MTProto call leaves the server:
| Guardrail | Default behavior | On violation |
|---|---|---|
Hard ceiling (hard_ceiling) |
Allows read, organize, send; moderation, deletion, account, and money tools stay locked even from /settings |
hard_ceiling_exceeded |
| Strict send whitelist | Starts empty; resolves @username live over MTProto against pinned numeric peer_id to catch handle takeovers |
not_whitelisted / username_mismatch |
| Read blacklist & framing | Drops blacklisted chats and contacts from dialogs, search, forwards, stories, and reply quotes before JSON serialization; wraps external text as [external data] |
read_blacklisted |
| SQLite rate limits & audit | 60/hr global, 20/hr per chat (survives restarts; forwarding 30 messages costs 30); fail-closed audit row written before every mutation | rate_limit_exceeded / audit_failed |
| File sandbox & kill switch | Uploads only from outbox_dir (O_NOFOLLOW); downloads stay in RAM (4 MiB cap); kill switch halts all sends immediately |
path_forbidden / sending_paused |
Full pipeline details and refusal codes: Security architecture and Threat model.
Quickstart
Grab a release archive from GitHub Releases or pull ghcr.io/ilodezis/gramcp, add api_id and api_hash from my.telegram.org, then sign in and allow Saved Messages:
./gramcp --config config.local.toml login # QR code, or phone + 2FA
./gramcp --config config.local.toml chats allow me --label "Saved Messages"
./gramcp --config config.local.toml doctor # checks 0600 permissions and config
Client configs for Claude, Codex, Antigravity, Docker, and remote OAuth 2.1: Install and Configuration.
Limits
gramcp is an MTProto userbot, not the Bot API. Telegram restricts accounts that look like spam; rate limits lower that risk without removing it. Policy bounds what a fooled model can do, not what it writes inside a chat you whitelisted. Read the threat model before widening defaults.