telegram-mcp
by StringKe
README.md
# telegram-mcp
[简体中文](README.zh-CN.md)
A local daemon that logs in to your own Telegram account over MTProto ([mtcute](https://github.com/mtcute/mtcute)) and exposes it to Claude Code (or any MCP client) as an MCP server: read, search and send messages, work with forum topics, manage folders, and watch a chat or topic for new replies in real time. It ships as a Claude Code plugin with skills that teach Claude how to use it and how to set it up.
- MCP over Streamable HTTP at `http://127.0.0.1:47101/mcp`
- New-message push over WebSocket at `ws://127.0.0.1:47101/watch`
- Catches up on messages missed while the machine slept or the daemon was stopped
It listens on `127.0.0.1` only and accepts only loopback `Host` and empty or loopback `Origin` headers (DNS rebinding and cross-site protection from the MCP SDK). There is no token.
## Install as a Claude Code plugin
At the Claude Code prompt:
```
/plugin marketplace add stringke/telegram-mcp
/plugin install telegram-mcp@telegram-mcp
```
Or from a shell:
```
claude plugin marketplace add stringke/telegram-mcp
claude plugin install telegram-mcp@telegram-mcp --scope user
```
Then ask Claude to "set up Telegram MCP", or run `/telegram-mcp:telegram-setup`. The setup skill copies the daemon to `~/.local/share/telegram-mcp/app`, installs dependencies, helps you get an `api_id` / `api_hash` from https://my.telegram.org, has you scan a login QR code in your own terminal, registers a launchd agent on macOS, and checks the result with `get_me`. Run setup again after updating the plugin so the background service picks up the new code.
The plugin contains two skills, `telegram` (how to read, search, send, use topics and watch for replies) and `telegram-setup` (install, login, background service, removal). Tools are named `mcp__plugin_telegram-mcp_telegram__<tool>`.
## Manual install (any MCP client)
Requires Bun 1.4 or newer.
```
git clone https://github.com/stringke/telegram-mcp.git
cd telegram-mcp
bun install --frozen-lockfile
bun run configure # prompts for api_id and api_hash, writes ~/.config/telegram-mcp/config.json (mode 600)
bun run login # shows a QR code; scan it in Telegram: Settings -> Devices -> Link Desktop Device
bun run service:install # macOS launchd agent; elsewhere run `bun run serve`
```
Register the server with your client, for example Claude Code:
```
claude mcp add --transport http --scope user telegram http://127.0.0.1:47101/mcp
```
| Command | What it does |
|---|---|
| `bun run configure` | Prompt for API credentials and save them |
| `bun run login` | QR login (asks for the 2FA password if set); reports the account if already logged in |
| `bun run serve` | Run the daemon in the foreground |
| `bun run service:install` | macOS: install the launchd agent `io.github.stringke.telegram-mcp` (starts at login, restarts on exit) |
| `bun run service:uninstall` | Stop and remove the agent |
The agent records the install directory and the Bun path; reinstall it after updating the code or upgrading Bun.
## Configuration
| Variable | Default | Purpose |
|---|---|---|
| `TELEGRAM_API_ID` / `TELEGRAM_API_HASH` | none | MTProto app credentials; take precedence over the config file when both are set |
| `TELEGRAM_CONFIG_DIR` | `~/.config/telegram-mcp` | `config.json` (API credentials) and your optional personal `voice.md` |
| `TELEGRAM_STATE_DIR` | `~/.local/state/telegram-mcp` | Session, inbox database and log |
| `TELEGRAM_DOWNLOAD_DIR` | `~/Downloads/telegram` | Default target of `download_media` |
| `TELEGRAM_MCP_PORT` | `47101` | Port (the plugin expects 47101) |
| `TELEGRAM_INBOX_RETENTION_DAYS` | `30` | How long inbox events are kept |
`user.session` in the state directory is your account's login: never share it. API credentials are never written to the launchd plist.
To make Claude write in your own style, copy `skills/telegram/voice.md` to `~/.config/telegram-mcp/voice.md` and edit it. The `telegram` skill reads it before sending, and its rules (including whether to ask before sending and whether to watch for replies automatically) override the defaults.
## Tools
All times are UTC ISO 8601 and all ids are strings. `chat` accepts `@username`, t.me links (including `t.me/c/...` and invite links), numeric ids, `+<country code><phone>` and `me`. Error messages and watch frames are in Chinese.
`get_me`, `list_dialogs`, `list_topics`, `get_history`, `get_messages`, `search_messages`, `get_new_messages`, `sync_now`, `get_chat`, `get_chat_members`, `add_chat_members`, `resolve`, `send_message`, `edit_message`, `delete_messages`, `forward_messages`, `mark_read`, `send_file`, `download_media`, `send_reaction`, `pin_message`, `list_folders`, `create_folder`, `update_folder`, `delete_folder`, `reorder_folders`, `mute_chat`, `unmute_chat`, `archive_chats`, `unarchive_chats`, `pin_dialog`, `mark_unread`, `join_chat`, `leave_chat`.
See [README.zh-CN.md](README.zh-CN.md) for each tool, forum topic behaviour, the `/watch` frame format and how catch-up works.
## Caveats
- This acts as you. Everything it sends is sent by you. Follow Telegram's API terms; do not use it for bulk messaging or spam, or the account may be limited.
- One session, one process. Two processes on the same session get both disconnected with `AUTH_KEY_DUPLICATED`, which is why clients share one daemon over HTTP instead of each spawning a stdio server. Stop the daemon before `bun run login`.
- Edits and deletions that happen while the daemon is stopped are not recovered; new messages are.
## Development
```
bun install
bun run typecheck
bun test
```
Tests are offline and never contact Telegram. Bump `version` in `.claude-plugin/plugin.json` for each release, otherwise installed copies do not update.
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues