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: kurigram-mcp
โจ 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, 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 any Relay model (image, video, audio, LLM), poll tasks, upload files and search Relay's docs.
141
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceDrives a personal Telegram account from the terminal or via MCP, enabling AI assistants to list chats, send/edit messages, fetch history, manage groups, and more with tiered read/write/destructive permissions.1MIT
- AlicenseNot gradedqualityBmaintenanceMCP server to debug Telegram bots by controlling your Telegram user session over MTProto. It enables sending messages, reading chats, handling updates, and invoking raw Telegram API methods.6MIT
- FlicenseNot gradedqualityCmaintenanceEnables interfacing with Telegram through user accounts or bots, offering tools for messaging, chat management, search, media sharing, and session control with flood-safe rate limiting.1-
- AlicenseNot gradedqualityBmaintenanceEnables AI coding agents to autonomously interact with, test, click inline buttons on, and verify Telegram bots end-to-end via MTProto.MIT