telegram-bot-testing-mcp
Enables AI agents to test Telegram bots by driving the official Telegram Web client in a real browser, allowing visual verification of bot responses, inline keyboards, and Mini Apps.
README
telegram-bot-testing-mcp
Write test scenarios for your Telegram bot — Claude runs them like a human QA.
AI agents can already test any website through browser automation. This MCP server gives them the same power over Telegram bots and Mini Apps: it drives the official Telegram Web client (web.telegram.org) in a real browser. Your agent gets exactly the input a real user gets — the same rendered chat, the same keyboards, the same Mini App — so it can verify not just that the bot responds, but that nothing is broken visually: keyboards render in the right shape, edits land, media shows up, the Mini App actually opens.
Instead of clicking through your bot by hand after every deploy, you describe the scenario once and let the agent execute it — sending /commands, pressing the buttons, uploading files, comparing what it sees against what you expected, and attaching screenshots as evidence.
No MTProto libraries, no session-string hacks, no bot token on the user side. Telegram sees a normal, official web client.
Why not telethon / Bot API?
- Bot API shows you the bot's side, not the user's. You can't see how your keyboard renders, whether the edit landed, or what a real user experiences.
- MTProto userbot libraries (telethon, gramjs, pyrogram) are custom clients: a different code path from real users, and account-ban-prone.
- This adapter is a real user session in the official client — what your agent sees is pixel-for-pixel what users see, structurally and visually.
Quickstart
# 1. Install (Python 3.11+; from GitHub until the PyPI release)
uv tool install git+https://github.com/0x216/telegram-bot-testing-mcp
# download the browser (playwright lives inside the tool's env, so go through uvx):
uvx --from git+https://github.com/0x216/telegram-bot-testing-mcp playwright install chromium
# 2. Log in once (opens a browser window — scan the QR with a dedicated account)
telegram-bot-testing-mcp login
# 3. Add to Claude Code
claude mcp add telegram -- telegram-bot-testing-mcp
Then hand your agent a scenario instead of testing by hand:
Run a regression pass on @my_bot:
/start— the welcome message must show the pricing keyboard, 2 rows of 2.- Press Buy — the bot must edit that message into a payment summary.
- Send
PROMO2026— the reply must confirm the discount.- Open the Mini App from the Catalog button and add the first item to cart.
- Screenshot every step and flag anything that renders wrong.
The agent executes it step by step with the same input a human tester would have, and reports what passed, what failed, and how it looked.
Tools
| Tool | Purpose |
|---|---|
tg_status |
Mode, login state, profile location |
tg_login |
One-time interactive login (QR window) |
tg_login_phone / tg_login_code / tg_login_password |
Headless login by phone number — the code arrives on the account's other devices |
tg_send_voice |
Record & send a real voice message through a fake microphone (WAV input) |
tg_open_chat |
Open chat by @username / t.me link |
tg_send_message |
Send text or /command |
tg_send_file |
Attach & send photo/document (with caption) |
tg_read_messages |
Last N messages as structured JSON (text, buttons grid, media kind, ids) |
tg_wait_for_message |
Block until the bot replies — the core test primitive |
tg_click_button |
Press an inline button by text or row/col |
tg_click_reply_button |
Press a reply-keyboard button |
tg_clear_chat |
Wipe history (test isolation) |
tg_screenshot |
Screenshot chat / single message / window |
tg_miniapp_open |
Open a Mini App from a web-app button |
tg_miniapp_snapshot |
List interactive elements inside the Mini App ([ref] role "text") |
tg_miniapp_click / tg_miniapp_type |
Interact with Mini App elements by ref |
tg_miniapp_screenshot / tg_miniapp_close |
Capture / close the Mini App |
All tools return typed errors with actionable hints (not_logged_in,
button_not_found + the buttons that are present, timeout + current chat
state, selector_broken when Telegram changes markup).
Configuration
| Env var | Default | Meaning |
|---|---|---|
TG_MCP_MODE |
prod |
prod or test (Telegram test DC, adds ?test=1) |
TG_MCP_HEADED |
off | 1 = show the browser window during operations |
TG_MCP_PROFILE_DIR |
~/.telegram-user-mcp/profile-<mode> |
Browser profile location |
Security
The browser profile directory is your Telegram session — treat it like a password. Use a dedicated test account, not your personal one: any automation that can send messages from your account is worth isolating. The profile stays on your machine; nothing is sent anywhere except to Telegram itself.
Headless servers (CI boxes, VPS)
Everything is headless by default, including login:
telegram-bot-testing-mcp login --phone +42077xxxxxxx
# the confirmation code arrives in the Telegram app on the account's
# other devices (or via SMS) — type it into the terminal prompt
Agents can do the same via tg_login_phone → tg_login_code
(→ tg_login_password for 2FA accounts).
Alternatively, log in once on a desktop machine (login opens a QR window)
and move the profile — it is just a directory and transfers fine across OSes
(verified Windows → Linux):
tar -czf tg-profile.tgz -C ~/.telegram-user-mcp profile-prod
scp tg-profile.tgz server:
ssh server 'mkdir -p ~/.telegram-user-mcp && tar -xzf tg-profile.tgz -C ~/.telegram-user-mcp'
Treat the archive like a password — it contains your session.
Testing against the Telegram test DC
Telegram runs a separate test environment, and TG_MCP_MODE=test targets it.
Reality check as of 2026:
- Auto-created test accounts are disabled. The documented
99966XYYYYnumbers with deterministic codes no longer work (tdlib/td#3370 — "Test accounts are disabled currently"). Don't believe older tutorials. - Register with a real phone number via the official iOS app: tap the Settings icon 10 times → Accounts → Login to another account → Test.
- Log the adapter in:
TG_MCP_MODE=test telegram-bot-testing-mcp login— scan the QR with the test-mode iOS app. - Create your bot inside the test DC: message
@BotFatherfrom the test account — it's a separate BotFather with separate tokens. - Point your bot's code at the test Bot API route:
https://api.telegram.org/bot<token>/test/METHOD(the bot is a token, not a phone number — one test account can create the bot and act as the user).
For most workflows the default prod mode with a dedicated account is simpler.
Limitations (v1)
- Designed for 1:1 bot chats; groups/channels are untested.
- One server instance per profile (Chromium locks the profile directory).
- Telegram Web markup changes can break selectors — they live in one file
(
selectors.py), and every breakage surfaces as a typedselector_brokenerror. PRs welcome.
Development
uv venv && uv pip install -e ".[dev]" && playwright install chromium
python -m pytest # unit tests (offline, fixture DOM)
python e2e/fixture_bot.py # BOT_TOKEN=... — the e2e fixture bot
python e2e/run_scenarios.py # BOT=@your_fixture_bot — full scenario run
MIT license.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。