Skip to main content

tgbot2mcp — Turn any Telegram bot into an MCP server

English | Русский | 中文

PyPI GitHub Python 3.11+ License: MIT


tgbot2mcp

Turn any Telegram bot into a ready-to-use MCP server in one command.
No bot token required. Works with any existing Telegram bot through your user account.

What is this? An open-source Python adapter that connects to Telegram as a user (via MTProto), auto-discovers a target bot's capabilities, and exposes them as MCP tools — so AI agents (Claude, GPT, Gemini) can interact with any Telegram bot.


Quick Start

One command to set everything up:

uvx tgbot2mcp setup @SomeBot

This will:

  1. Ask for your Telegram API credentials (from my.telegram.org/apps)
  2. Log in to Telegram
  3. Verify the bot is reachable
  4. Auto-configure your MCP client (Claude Desktop / Cursor / VS Code)

Done. Your AI agent can now talk to the bot.


Installation

uvx (recommended — no install needed)
uvx tgbot2mcp setup @SomeBot
uvx tgbot2mcp serve @SomeBot

Requires uv.

pipx (permanent install)
pipx install tgbot2mcp
tgbot2mcp setup @SomeBot
Docker (HTTP/self-hosted)
docker run --rm -it \
  -p 8080:8080 \
  -v tgbot2mcp-data:/data \
  -e TG_API_ID=123456 \
  -e TG_API_HASH=... \
  ghcr.io/megamen32/tgbot2mcp \
  serve @SomeBot --transport http --host 0.0.0.0 --port 8080
From source (development)
git clone https://github.com/megamen32/tgbot2mcp.git
cd tgbot2mcp
pip install -e ".[dev]"
tgbot2mcp setup @SomeBot

How It Works

┌─────────────┐     MTProto      ┌─────────────┐      MCP       ┌─────────────┐
│  Telegram    │ ───────────────▶ │  tgbot2mcp  │ ─────────────▶ │  AI Agent   │
│  Bot (@bot)  │ ◀─────────────── │             │ ◀───────────── │ (Claude etc)│
└─────────────┘   Bot responses   │  • Discover │   Tool calls   └─────────────┘
                                   │  • Interact │
                                   │  • Expose   │
                                   └─────────────┘
  1. Authenticate — Log in with your Telegram account (phone number)
  2. Discover — Crawl the bot: /start, /help, buttons, full state graph via DFS
  3. Expose — Every action becomes an MCP tool
  4. Interact — AI agents send messages, click buttons, navigate states

MCP Tools

Universal (always available)

Tool What it does
send Send text or /command and get the response
click Click an inline or reply-keyboard button
read Read recent messages from the conversation
wait Wait for a delayed bot response
reset Reset conversation state
discover List all auto-discovered commands and buttons

Dynamic (auto-generated from bot discovery)

  • cmd_{name} — one tool per slash command (cmd_start, cmd_help, etc.)
  • btn_{label} — one tool per button found in bot responses

MCP Client Configuration

Claude Desktop

{
  "mcpServers": {
    "telegram-bot": {
      "command": "uvx",
      "args": ["tgbot2mcp", "serve", "@YourBot"],
      "env": {
        "TG_API_ID": "YOUR_API_ID",
        "TG_API_HASH": "YOUR_API_HASH"
      }
    }
  }
}

Tip: tgbot2mcp setup writes this config for you automatically.

Cursor / VS Code

Same format — saved to ~/.cursor/mcp.json or ~/.vscode/mcp.json by setup.


Commands

Command Description
tgbot2mcp setup @Bot Full onboarding wizard (credentials + login + MCP config)
tgbot2mcp login Telegram authentication only
tgbot2mcp serve @Bot Start MCP server (stdio or HTTP)
tgbot2mcp inspect @Bot Show discovered bot capabilities
tgbot2mcp generate @Bot Generate standalone MCP server file

Serve options

# stdio (default — for Claude Desktop, Cursor)
tgbot2mcp serve @SomeBot

# HTTP transport (for remote/self-hosted)
tgbot2mcp serve @SomeBot --transport http --port 8080

# Skip discovery (universal tools only, faster startup)
tgbot2mcp serve @SomeBot --no-discover

Configuration

Config: ~/.tgbot2mcp/config.yaml

api_id: 12345
api_hash: "your_api_hash"
session_dir: ~/.tgbot2mcp/sessions
default_timeout: 20.0
discovery_max_depth: 5

Environment variables (override config):

  • TG_API_ID / TELEGRAM_API_ID
  • TG_API_HASH / TELEGRAM_API_HASH

FAQ

Do I need the bot's API token? No. tgbot2mcp uses your Telegram user session (MTProto). Works with any bot, even ones you don't own.
Is this safe? Session files (~/.tgbot2mcp/sessions/) give full access to your Telegram account. Never share them. Created with 0600 permissions.
Which AI clients work? Any MCP client: Claude Desktop, Cursor, Continue (VS Code), Cline, and others. Supports stdio and HTTP transports.
Can I use it with any bot? Yes. Any public Telegram bot that accepts messages will work.

Architecture

Component Source Role
Discovery BotFuzzer DFS crawling, state graph
Interaction TgTestKit Messages, buttons, edited messages
MCP MCP Python SDK Protocol implementation
Transport Telethon (MTProto) User-session Telegram access

License

MIT


🇷🇺 Русский

tgbot2mcp — превращает любого Telegram-бота в MCP-сервер одной командой.
Токен бота не нужен — работает через ваш аккаунт.

uvx tgbot2mcp setup @SomeBot

Мастер настройки сам запросит API-ключи, выполнит авторизацию, проверит бота и настроит MCP-клиент (Claude / Cursor / VS Code).

Ручной запуск:

uvx tgbot2mcp login
uvx tgbot2mcp serve @SomeBot

Нужен uv и API-ключи с my.telegram.org/apps.


🇨🇳 中文

tgbot2mcp — 一条命令将任何 Telegram 机器人变为 MCP 服务器。
无需机器人 Token,通过您的用户账户运行。

uvx tgbot2mcp setup @SomeBot

设置向导会自动请求 API 密钥、完成登录、验证机器人并配置 MCP 客户端(Claude / Cursor / VS Code)。

手动运行:

uvx tgbot2mcp login
uvx tgbot2mcp serve @SomeBot

需要 uv 和 my.telegram.org/apps 的 API 密钥。


Built with Telethon · MCP Python SDK · Inspired by BotFuzzer & TgTestKit

Release files for tgbot2mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tgbot2mcp 0.1.0
File Size Uploaded
tgbot2mcp-0.1.0.tar.gz 27.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tgbot2mcp 0.1.0
File Interpreter ABI Platform
tgbot2mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 54.3 kB

Release files / tgbot2mcp-0.1.0.tar.gz

Download URL tgbot2mcp-0.1.0.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0ac7e7e68bbeebd6bc573ce0c3a3871e2071cc4089fab4ddc944fa74d8d2540a
BLAKE2b-256 checksum
How to use checksums
e00d8f4bfac84eacec57c09f8f6c981103eecb76b6a07452bd9b80c8a83bf9be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tgbot2mcp-0.1.0-py3-none-any.whl

Download URL tgbot2mcp-0.1.0-py3-none-any.whl
Size 26.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
240e59aaf227d6ca668f295fdcdd0ce8a2dd6dce76e100fa03aaad9f4bec5225
BLAKE2b-256 checksum
How to use checksums
5d529319bab58e4e9a66c3f882e9b8f995b77ea2eccf2a39f5428049d8c7fe73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page