Self-hosted MCP server: Telegram userbot control (Telethon) via HTTP and MCP.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
Your Telegram account, but it takes HTTP requests. Wraps Telethon β the real MTProto userbot client, not that neutered Bot API garbage β behind a JSON HTTP API and a Model Context Protocol endpoint.
Same tools, two doors. POST some JSON, or point your AI agent at /mcp and let it go nuts. Either way it's talking to Telegram as you, with full account access.
One login. One session string. Never type a code again.
One Telethon client. One async lock. Both surfaces share the same tool registry β no duplication, no weird state, no bullshit.
Get API_ID / API_HASH from https://my.telegram.org/apps. Get the session string from the login helper below.
Telegram makes you prove you're a human once β phone number, SMS code, optionally 2FA. Do it once, never again.
make login builds the image, runs the interactive flow, and shoves TELETHON_SESSION straight into your .env. That's it. Run make run and you're live.
No repo? No problem:
Copy the session string it spits out, set it as TELETHON_SESSION, done.
The session string is full account access. Whoever has it is you. Don't commit it, don't paste it in Slack, don't tattoo it anywhere.
All config via environment variables. Copy .env.example to get the full list with comments.
| Variable | Required | Default | Description |
|---|---|---|---|
TELETHON_API_ID | yes | β | API ID from my.telegram.org |
TELETHON_API_HASH | yes | β | API hash from my.telegram.org |
TELETHON_SESSION | yes | β | StringSession from the login helper |
TELETHON_HTTP_LISTEN_ADDRESS | no | 0.0.0.0:8080 | host:port to bind |
TELETHON_LOG_LEVEL | no | INFO | DEBUG, INFO, WARNING, ERROR |
TELETHON_REQUEST_TIMEOUT | no | 60 | Per-request timeout in seconds |
TELETHON_FLOOD_SLEEP_THRESHOLD | no | 60 | Auto-sleep through FLOOD_WAIT errors below this many seconds. Telegram will rate-limit you β this is the safety valve. |
TELETHON_DEVICE_MODEL | no | docker-telethon-plus | What Telegram thinks your device is |
TELETHON_SYSTEM_VERSION | no | 1.0 | Ditto for OS |
TELETHON_APP_VERSION | no | 1.0 | Ditto for app |
TELETHON_DOWNLOAD_DIR | no | /tmp/telethon-plus | Scratch space for send_file uploads |
TELETHON_AUTH_KEY | no | "" | When set, all endpoints require Authorization: Bearer <key>. /healthz stays public. Empty = no auth. |
Telegram bans accounts that hammer it. Defaults here are conservative β meant to keep you under the server-side limits without you having to think about it. Tune only if you know what you're doing.
| Variable | Default | What it does |
|---|---|---|
TELETHON_THROTTLE_ENABLED | true | Master switch for all rate-limiting below |
TELETHON_THROTTLE_GLOBAL_INTERVAL_MS | 50 | Min gap between any two outgoing requests |
TELETHON_THROTTLE_JITTER_MS | 200 | Random Β±jitter added on top (kills metronome traffic patterns) |
TELETHON_THROTTLE_PER_CHAT_INTERVAL_MS | 1100 | Min gap between sends to the same chat (Telegram's "1/sec/chat" ceiling, with margin) |
TELETHON_THROTTLE_PER_CHAT_READ_INTERVAL_MS | 250 | Min gap between reads from the same chat. Stops single-channel scraping from monopolizing the read bucket. |
TELETHON_THROTTLE_ADAPTIVE | true | On each FLOOD_WAIT, multiply all waits Γ2 for an hour. Resets after a quiet hour. |
TELETHON_BUCKET_RESOLVE_PER_MIN | 5 | Cap on resolveUsername β the main thing that gets accounts 22-hour-banned |
TELETHON_BUCKET_GET_FULL_PER_MIN | 10 | Cap on getFullChannel / getFullUser / get_participants |
TELETHON_BUCKET_JOIN_PER_HOUR | 5 | Cap on channel/group joins |
TELETHON_BUCKET_CREATE_PER_HOUR | 5 | Cap on channel/group creation |
TELETHON_BUCKET_SEND_PER_MIN | 20 | Cap on sends across all chats |
TELETHON_BUCKET_READ_PER_MIN | 600 | Cap on read ops. Counted per server-side API call, not per tool call: get_messages(limit=300) charges 3 slots (Telegram caps GetHistory at 100/page); get_dialogs(limit=500) similarly charges 5. |
TELETHON_CACHE_ENABLED | true | Persist resolved entities to disk |
TELETHON_CACHE_PATH | /cache/entities.json | Mount /cache as a host volume to keep this across rebuilds |
TELETHON_CACHE_TTL_SECONDS | 604800 | 7 days. Set 0 for no expiry. |
TELETHON_FLOOD_SLEEP_THRESHOLD | 60 | Telethon's reactive auto-sleep: if a FLOOD_WAIT is shorter than this many seconds, sleep through it. Above this, raise. Set very high (e.g. 86400) to never raise β but then a hostile FLOOD_WAIT will block your process for the full duration. |
How the layers stack:
@somechannel calls Telegram; every subsequent lookup is free. Survives container restarts via the /cache volume.For bulk scraping work (the scenario that caused 22-hour bans before): the cache + bucket_resolve_per_min=5 combination is what saves you. Resolving 200 new channels takes ~40 minutes instead of getting you banned in 5.
JSON in, JSON out. All inputs are pydantic-validated β send garbage, get a 400 back with exactly what's wrong.
Chat references (chat, from_chat, to_chat) accept whatever Telethon accepts:
| Format | Example |
|---|---|
| Username | @psyb0t |
| Phone number | +1234567890 |
| t.me link | https://t.me/psyb0t |
| Numeric ID | 123456789 |
| Supergroup/channel ID | -1001234567890 |
| Your own Saved Messages | me |
Numeric IDs only resolve for entities Telethon has already seen β i.e. cached in your session via a prior
@username/t.melookup, dialog list, or incoming message. MTProto needs anaccess_hash, not just an ID, and bare numbers don't carry one. Especially relevant for bots: pass@botusernamefirst (or callGET /api/dialogs/GET /api/entities?chat=@botonce) before referring to it by numeric ID. If you only have the bot's token and no username, hit Telegram's Bot APIgetMeto fetch the username, then use that.
Every 2xx returns the resource directly. No {"result": ...} wrapper, no envelope. Lists are JSON arrays, singles are JSON objects.
Errors return {"detail": "..."} (FastAPI standard). Telegram RPC errors arrive as 502 with detail = {"telegram_error": "...", "message": "..."}.
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/telethon-plus)<a href="https://allmcps.com/mcp/telethon-plus"><img src="https://allmcps.com/api/badge/telethon-plus?style=directory" alt="Telethon Plus on AllMCPs" /></a>