Telegram MCP Server
# Telegram MCP Server v2.0
> **100% Pure Official MCP** Mobile Remote Control Hub for AI Coding Agents
> Native support for **Antigravity Desktop App / `agy` CLI** · **Claude Code Desktop App / `claude` CLI** · **Claude Desktop** · **Codex Desktop App / `codex` CLI**
[](https://www.python.org/)
[](https://modelcontextprotocol.io/)
[](#tos-compliance-by-design)
[](LICENSE)
English | [简体中文](README-CN.md)
---
## ToS Compliance by Design
In 2026, Google (Antigravity Additional Terms Section 6), Anthropic (Claude Code Legal & Compliance), and OpenAI all restrict third-party wrappers, OAuth credential extraction, and cross-agent CLI orchestration on personal subscriptions.
**Telegram MCP Server v2.0 is deliberately 100% pure MCP:**
- **Zero OAuth access**: never reads, proxies, or stores vendor login tokens.
- **Zero CLI wrapping or cross-agent spawning**: never launches `agy` / `claude` / `codex` subprocesses on your behalf.
- **100% official MCP protocol**: you launch official Antigravity, Claude Code, or Codex sessions yourself; this server solely bridges structured reports, approvals, questions, files, and human instructions with your Telegram app.
---
## Highlights of v2.0
- **MCP 2.x Native (`MCPServer`)**: Supports both `stdio` and `streamable-http` transports, MCP `roots/list` workspace discovery, `client_info` fingerprinting, one-command `tgbot` prompt, and read-only `telegram://sessions` resource.
- **Built for Both Desktop Apps & CLIs**:
- Collision-free session IDs (`agy-app-webapp-7f2c`, `claude-api-9a1e`, `codex-cli-4d8b`) + short aliases (`/rename`).
- **24-hour persistent waiting** (`86400s` default on Antigravity App/CLI, Claude Code App/CLI, and Codex App/CLI; `50s` chunked wait on standalone Claude Desktop) + **15s MCP progress heartbeats** so long sessions never disconnect or spam duplicate sessions.
- Explicit `telegram_register_session(project_path=...)` so Desktop Apps launched from `/` or `$HOME` always bind to the real workspace.
- **SQLite WAL Multi-Process Store + Resilient Leader Failover**:
- Replaces legacy JSON files with ACID SQLite WAL (`~/.telegram-mcp/state.db`), cross-platform atomic OS file locks (`flock` / `msvcrt`), and automatic standby takeover within 2.5s.
- **0.5-second local wakeup** when you reply on Telegram (down from 30–120s in v0.2.x).
- **Optional Dedicated Hub Daemon (`telegram-mcp-server daemon start`)**:
- Keep one stable Bot process running in the background while opening/closing Desktop Apps and terminals freely; add `--http --port 8765` for a shared MCP Streamable HTTP endpoint.
- **Hardened Security & Reliability**:
- Strict Chat/User ID allowlist on every command, message, attachment, and callback.
- Workspace-jailed `/file` and `/ls` (blocks `../` traversal).
- HTML-safe Telegram rendering with auto-chunking and plain-text fallback.
- Exact `message_id -> (session_id, question_id)` swipe-reply routing.
---
## Quick Start
### 1. Install
```bash
# Recommended: install latest v2.0 directly from GitHub via uv
uv tool install --force git+https://github.com/archetyx/telegram-mcp-server.git
# Or via pip:
pip install --upgrade git+https://github.com/archetyx/telegram-mcp-server.git
# Or from a local checkout:
uv tool install --force .
```
> Note: verify you are running v2.0 with `telegram-mcp-server --version` (PyPI may still serve legacy `0.2.4` until `2.0.0` is published).
### 2. Guided Multi-Client Setup
```bash
telegram-mcp-server setup
```
Detects and configures:
- **Antigravity Desktop App / IDE / `agy` CLI** → `~/.gemini/config/mcp_config.json`
- **Claude Code CLI / Desktop App** → `~/.claude.json` + `~/.claude/settings.json`
- **Claude Desktop** → OS-specific `claude_desktop_config.json`
- **Codex Desktop App / `codex` CLI** → `~/.codex/config.toml`
- Shared credentials in `~/.telegram-mcp/config.json` (`0600`) + one-command **`/tgbot`** slash-command skill installation (`telegram-mcp-server install-skill`) across Antigravity (`~/.gemini/config/skills/tgbot/SKILL.md`), Claude Code (`~/.claude/skills/tgbot/SKILL.md` + `~/.claude/commands/tgbot.md`), and Codex (`~/.codex/skills/tgbot/SKILL.md` + `~/.codex/prompts/tgbot.md`).
### 3. One-Command Activation: Just Type `/tgbot`
After restarting Antigravity, Claude Code, or Codex, simply type:
- **`/tgbot`** — registers the current workspace, sends a ready card with starter buttons to Telegram, and enters the unattended remote loop.
- **`/tgbot <your task>`** — registers the workspace, executes the task, reports results with action buttons, and waits for your next mobile instruction.
- **`/tgbot once <your task>`** — non-blocking mode: executes the task, sends the report to Telegram, and immediately returns control to your desktop chat without entering `telegram_wait`.
### 4. Optional Dedicated Hub Daemon & Diagnostics
```bash
telegram-mcp-server daemon start
# Or with shared MCP Streamable HTTP at http://127.0.0.1:8765/mcp:
telegram-mcp-server daemon start --http --port 8765
# Diagnostics
telegram-mcp-server doctor
```
---
## Core MCP Tools (8 Pure MCP Tools)
| Tool | Purpose |
|---|---|
| `telegram_register_session` | Bind/update session alias & real workspace `project_path` (essential for Desktop Apps) |
| `telegram_report` | Send structured reports (`completed`/`progress`/`error`/`info`) + up to 6 one-tap action buttons |
| `telegram_ask` | Atomic question / decision / approval prompt + wait with 15s MCP progress heartbeats |
| `telegram_wait` | Wait for next instruction (`unattended`) or reply (`reply`) with 0.5s wakeup & chunked timeout continuation |
| `telegram_check_inbox` | Non-blocking inbox peek/pop for mid-task course corrections |
| `telegram_send_code` | Syntax-highlighted code/diff sender (auto-uploads as file when large) |
| `telegram_send_file` | Smart image (photo) or document sender resolved relative to `project_path` |
| `telegram_session_info` | Context, token usage, uptime & read-only peer session overview |
---
## Telegram Commands
- `/sessions` (`/s`) — Interactive multi-session dashboard (switch, inspect, prune offline)
- `/use <id|alias|off>` — Pin/unpin active session
- `/to <id|alias> [message]` — Send instruction & switch active session (supports alias or unique prefix/suffix)
- `/status [id]` — Detailed session state, PID, queue depth & last report
- `/rename [id] <alias>` — Assign a short friendly alias
- `/exit [id]` — Exit remote wait mode gracefully and release your desktop chat
- `/stop [id]` / `/clear [id]` / `/close <id>` — Signal stop, clear inbox queue, or close session
- `/ls [id] [subpath]` / `/file [id] <path> [download]` — Sandboxed workspace browser & file viewer
- `/launch` — ToS-safe manual launch tips for Antigravity, Claude Code & Codex
---
## Development & Tests
```bash
uv venv .venv
uv pip install --python .venv/bin/python -e ".[dev]"
.venv/bin/pytest -v
```
## License
MIT License — see [LICENSE](LICENSE).
TDQS
Scored across 8 tools
Most tools have distinct purposes: get_context_info for session info, notify for structured notifications, send for free messages, send_code for code snippets, send_file for files, send_image for images, unattended_mode for task loops, and wait_reply for blocking replies. However, send and notify could be confused as both send messages, though descriptions clarify notify is preferred for structured content.
All tools follow a consistent 'telegram_' prefix with snake_case naming (e.g., telegram_get_context_info, telegram_notify). The verb-noun pattern is clear and uniform across all eight tools, making them easily identifiable and predictable.
With 8 tools, the set is well-scoped for a Telegram integration server. It covers core functionalities like sending messages, files, images, and code, plus advanced features like context retrieval and unattended modes, without being overwhelming or lacking essential operations.
The toolset provides comprehensive coverage for Telegram communication, including sending various content types, receiving replies, and managing sessions. A minor gap is the lack of tools for managing Telegram-specific entities like chats or users, but the focus on agent notification workflows is well-covered.