tgbot-mcp

tgbot-mcp

A trusted, open-source MCP server for Telegram that enables LLMs to send messages, structured notifications with buttons, and wait for user replies using only bot token authentication.

Category
访问服务器

README

tgbot-mcp

PyPI version Python License: MIT

A trusted, open-source MCP (Model Context Protocol) server for Telegram.

Built as a clean alternative to closed-source or opaque Telegram MCP packages — bot token authentication only, no personal account access, no proprietary backend.


Features

  • Bot token auth only — uses the official Telegram Bot API (api.telegram.org). Your personal account is never touched.
  • 4 purpose-built tools for LLM workflows: send messages, send structured notifications, send notifications with action buttons, and wait for user replies.
  • Language-agnostic — tools are written in English, but the LLM responds to users in their own language automatically. No language is hardcoded.
  • Smart polling in wait_for_reply to minimise API calls while staying responsive.
  • Zero external services. Pure Python + httpx + fastmcp.

Quick Start

1. Create a Telegram Bot

  1. Open Telegram and message @BotFather.
  2. Send /newbot and follow the prompts.
  3. Copy the bot token (looks like 123456:ABC-DEF...).
  4. Start a chat with your new bot, then visit:
    https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
    
    Send any message to the bot and look for "chat":{"id":...} — that is your chat ID.

2. Register with Your MCP Client

Add the following to your MCP client configuration (e.g. claude_desktop_config.json):

{
  "mcpServers": {
    "tgbot-mcp": {
      "command": "uvx",
      "args": ["tgbot-mcp"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "YOUR_BOT_TOKEN",
        "TELEGRAM_CHAT_ID": "YOUR_CHAT_ID"
      }
    }
  }
}

uvx runs the server directly from PyPI without a separate install step. If you don't have uv yet:

curl -LsSf https://astral.sh/uv/install.sh | sh

Alternatively, install manually and run with pip:

pip install tgbot-mcp

Then use "command": "tgbot-mcp" (without uvx) in the config above.


Tools

send_message

Send a free-form text message to the configured chat.

Parameter Type Default Description
text str (required) Message body. Telegram Markdown supported.
parse_mode "Markdown" | "HTML" | "" "Markdown" Text formatting mode.

Example prompt: "Send a Telegram message: 'Build finished successfully in 2m 14s.'"


send_notification

Send a structured notification with an automatic event emoji.

Event Emoji
completed
error
progress 🔄
question
Parameter Type Default Description
event str (required) One of the four event types above.
summary str (required) One-line summary (≤200 chars).
details str "" Optional multi-line detail body.

Example prompt: "Notify me on Telegram that the data pipeline completed. Include row counts."


send_notification_with_buttons

Send a notification with up to 4 inline action buttons. Ideal when you want the user to pick an option without typing.

Parameter Type Default Description
event str (required) Event type.
summary str (required) One-line summary.
buttons list[str] (required) 1–4 button labels. Each label is also the reply value.
details str "" Optional context text.

Example prompt: "Ask me via Telegram whether to deploy to staging or production."


wait_for_reply

Block until the user replies (text message or button tap) or the timeout expires.

Parameter Type Default Max Description
max_wait_seconds int 1800 no limit How long to wait for a reply.

Smart polling schedule:

Elapsed time Poll interval
0 – 10 minutes 30 seconds
10 minutes – 1 hr 60 seconds
1 hr+ 120 seconds

LLM guidelines for max_wait_seconds:

Scenario Recommended value
Simple yes/no question 300 (5 min)
General task approval 1800 (30 min) ✓
Stock price / event alert 1800 (30 min)
End-of-day review 7200 (2 hr)
Overnight / long-running job 86400 (24 hr)
Multi-day wait any value — no limit

Typical LLM Workflow

LLM: [does some long task]
  → send_notification_with_buttons(
        event="question",
        summary="Finished analysis. What should I do next?",
        buttons=["📊 Generate report", "📧 Send email", "🔁 Re-run with new params"]
    )
  → wait_for_reply(max_wait_seconds=1800)
  → [user taps "📊 Generate report"]
LLM: [generates the report]
  → send_notification(event="completed", summary="Report ready!", details="...")

Environment Variables

Variable Required Description
TELEGRAM_BOT_TOKEN Bot token from @BotFather
TELEGRAM_CHAT_ID Chat ID to send messages to

Development

# Clone and install in editable mode
git clone https://github.com/TGLEEEE/tgbot-mcp
cd tgbot-mcp
pip install -e ".[dev]"

# Run directly
TELEGRAM_BOT_TOKEN=... TELEGRAM_CHAT_ID=... python -m tgbot_mcp.server

Security

  • Only the official Telegram Bot API is used (api.telegram.org). No third-party relay.
  • Bot tokens are read from environment variables — never hardcoded.
  • Only the chat configured via TELEGRAM_CHAT_ID receives messages.
  • No personal Telegram account credentials are ever required.

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选