telegram-mcp-cli
Allows interacting with and automating Telegram bots directly from the terminal, including sending messages, triggering commands, clicking inline buttons, live chat sessions, and executing MTProto snippets.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@telegram-mcp-clisend 'Hello from terminal' to @my_bot"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
โก telegram-mcp-cli
Modern Command-Line Interface & Bot Automation Controller for Telegram
๐ Table of Contents
Related MCP server: HT MCP Server
โจ Key Features
๐ Instant Session Switching (
tg-cli auth <path.session>): Pass any existing Telethon.sessionfile directly. Automatically validates SQLite integrity, detects the target server cluster, and aligns settings.๐ค Bot Testing & Automation: Send text payloads, trigger slash commands (e.g.
/start), inspect responses, and click inline keyboard buttons.๐ก๏ธ Environment Mismatch Shield: Automatically detects whether your session belongs to the Test Server (Sandbox) or Production Server and protects against cross-environment auth revocation.
๐ Process-Level Session Guard: Prevents concurrent duplicate connections (
/tmp/telegram-mcp.lock) to eliminateAuthKeyDuplicatedError.๐ Rich Terminal Display: Colorized output, message panels, button trees, and clean tabular diagnostics powered by
rich.๐ฌ Real-Time Interactive Chat (
tg-cli chat <@bot>): Live terminal chat session with background streaming of incoming messages, inline button triggers (/click), and history scrolling.โก Arbitrary MTProto Execution (
tg-cli exec): Direct command-line evaluation of Python MTProto snippets with live client injection.
๐๏ธ Architecture
flowchart TD
subgraph Terminal ["User / Agent CLI"]
CLI["tg-cli (argparse + rich)"]
end
subgraph Core ["telegram-mcp-cli Engine"]
Config["Config Manager (.env)"]
Shield["Environment Mismatch Shield"]
Lock["Process Lock (/tmp/telegram-mcp.lock)"]
Controller["TelegramCliClient (Telethon)"]
end
subgraph Telegram ["Telegram MTProto Network"]
TestDC["Telegram Test DC (Sandbox)"]
ProdDC["Telegram Production DC (Live)"]
end
CLI --> Config
CLI --> Controller
Controller --> Lock
Controller --> Shield
Shield -->|Test Session| TestDC
Shield -->|Prod Session| ProdDC๐ Quick Start
1. Installation
From PyPI (Recommended):
pip install telegram-mcp-cliFrom Source:
git clone https://github.com/Telegram-mcp/telegram-mcp-cli.git
cd telegram-mcp-cli
pip install -e .2. Configure Authentication
If you already have atelegram-mcp installation at /root/bot-mcp, tg-cli automatically detects and shares credentials from its .env!
To set up or switch active sessions directly:
# Option A: Point to an existing Telethon .session file
tg-cli auth /path/to/my_account.session
# Option B: Run interactive phone / QR login
tg-cli auth login3. Verify Connection
tg-cli status๐ป Command Reference
Command | Description | Example |
| Configure active session file or login |
|
| View connection, DC, and account status |
|
| Send formatted text message to a bot/chat |
|
| Send |
|
| Click inline button by text or index |
|
| Start interactive live chat session |
|
| Fetch recent conversation history |
|
| Upload photo, document, or audio |
|
| Execute MTProto Python snippet |
|
| Release session lock & terminate conflicting process |
|
๐ก๏ธ Safety & Session Protection
Telegram permanently revokes authorization keys if multiple processes connect with the same session key simultaneously (AuthKeyDuplicatedError).
File Locking:
tg-cliuses/tmp/telegram-mcp.lockto ensure no two processes use the session concurrently.Instant Lock Clearing (
tg-cli unlock): If a background MCP server or orphaned process holds the lock, runtg-cli unlockto cleanly terminate it and free the lock.Force Takeover (
--force): Pass--forceto any command (e.g.tg-cli chat @bot --forceortg-cli status --force) to automatically terminate conflicting background processes before connecting.Environment Matching: Test Server sessions (DC 2 Sandbox) and Production sessions cannot be cross-connected. The CLI will abort with a clear warning before Telegram revokes the key.
๐งช Testing
Run the automated unit test suite with pytest:
python3 -m pytest tests -v๐ License
This project is licensed under the MIT License.
This server cannot be deployed
Maintenance
Related MCP Connectors
Multi-tenant Telegram gateway for AI agents โ HTTP+stdio, 8 tools, MTProto User API
I use your linked Telegram MTProto session (Integrations โ Telegram) to list groups, members, and sโฆ
Telegram bridge for your MCP-compatible agent. Bidirectional, no LLM in our stack.
Run AI customer support from your terminal: conversations, knowledge base, and chat widget.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables programmatic control over tmux terminal sessions for SSH access, command execution, and terminal automation. Supports creating sessions, sending commands, capturing output, and managing multiple panes for interactive debugging and monitoring.88 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to programmatically control interactive terminal applications through HT sessions, supporting session management, key sending, snapshots, and command execution.1MIT
- AlicenseBqualityCmaintenanceEnables stateful subprocess sessions (REPLs) and tmux-backed TUI program control for interactive tools like Python, r2, or shells.13AGPL 3.0
- AlicenseNot gradedqualityFmaintenanceEnables AI assistants to test Terminal User Interface (TUI) applications by launching, interacting with, and verifying programmatic output and behavior.17MIT