telegram-bot-mcp

telegram-bot-mcp

Lets Claude manage a Telegram channel through the Bot API, including tracking subscriber growth and publishing, editing, pinning, or deleting posts.

Category
访问服务器

README

telegram-bot-mcp

An MCP server that lets Claude manage a Telegram channel through the Telegram Bot API — track subscriber growth day over day, and publish, edit, pin, or delete posts.

🇮🇷 راهنمای فارسی · Deployment guide · راهنمای دپلوی


What this is

Telegram's Bot API is a plain HTTPS API. This repository wraps it in the Model Context Protocol so an AI assistant can call it as tools — "how did the channel do this week?" instead of curl https://api.telegram.org/bot.../getChatMemberCount.

It ships in two forms, from the same tool definitions:

Remote server (remote/) Local plugin (plugin/)
Runs on Val Town (or any Deno-compatible host) Your own machine
Connects via Claude custom connector (OAuth) Claude Code plugin (stdio)
Works in Claude web, desktop, mobile, scheduled tasks Claude Code CLI
Persistence Val Town blob storage CSV file on disk
Auth Built-in OAuth 2.1 + password gate Local config file
Needs your computer on No Yes

Pick the remote server if you want daily reports that run without you. Pick the plugin if you only use Claude Code and prefer nothing leaving your machine.

Tools

Both builds expose the same eight tools.

Tool Description
get_channel_info Title, username, description, subscriber count, admin count, invite link
get_member_count Subscriber count only — fast
snapshot_members Record today's count, return the change since the previous snapshot
get_growth_history Recorded snapshots with per-day changes and a net-change summary
send_post Publish a text post (HTML/Markdown, silent, no-preview options)
edit_post Replace the text of a post
delete_post Delete a post by message id
pin_post Pin or unpin a post

Quick start (remote server)

  1. Create a bot with @BotFather → /newbot → copy the token.
  2. Add the bot as an administrator of your channel.
  3. Create an HTTP val on val.town and paste in remote/telegram-mcp.ts.
  4. Set three environment variables in the val's sidebar: TELEGRAM_BOT_TOKEN, TELEGRAM_CHANNEL, MCP_PASSWORD.
  5. In Claude: Settings → Connectors → Add custom connector → https://<your-val>.web.val.run/mcp → enter your password.

Full walkthrough, including the local plugin path and troubleshooting: docs/deployment.md.

Security

No credentials are committed to this repository. config.json and .env are gitignored; only .example files are tracked. Before pushing any fork, confirm with git status that neither appears.

The remote server implements a full OAuth 2.1 authorization flow rather than sitting open on the internet:

  • Requests without a valid bearer token get 401 with a WWW-Authenticate header pointing at the resource metadata, per RFC 9728.
  • Clients register dynamically (RFC 7591); no client secrets to distribute.
  • Authorization codes are protected with PKCE (S256), and redirect URIs are validated against the registered set.
  • Access and refresh tokens are HMAC-SHA256 signed and stateless — 24-hour access, 30-day refresh.
  • The consent screen is gated by MCP_PASSWORD, which you choose.

Your bot token stays in the host's environment variables and is never returned by any tool.

Treat MCP_PASSWORD like a password to your channel. Anyone who has it can connect and publish posts.

Limitations

The Bot API reports subscriber counts only. Post views, forwards, reach, and Telegram's official channel-statistics graphs are not exposed to bots — those require an MTProto client signed in with a user account that administers the channel.

A bot can generally only edit messages it sent itself. Telegram defines a can_edit_messages administrator right ("can edit messages of other users; for channels only"), but bot behaviour against posts published by human admins is not clearly documented — test it against your own channel before relying on it. Deletion is different: can_delete_messages explicitly covers other users' messages.

Growth comparison requires the history store to survive between runs. On Val Town that is blob storage and it persists. In the local plugin it is a CSV file — keep it somewhere durable, not a temp directory.

Repository layout

remote/telegram-mcp.ts              Remote MCP server (Val Town HTTP val, Deno)
plugin/                             Claude Code plugin
  .claude-plugin/plugin.json          Plugin manifest
  .mcp.json                           stdio MCP server registration
  server/telegram_mcp_server.py        MCP server (Python 3, stdlib only)
  skills/telegram-channel-report/      Skill that turns tools into a readable report
  config.example.json                  Template — copy to config.json
tests/                              Test suite for the remote server
docs/                               Deployment guides (English / فارسی)

Tests

npm test

Requires Node 22.6+. Twenty-two checks cover the OAuth flow (401 challenge, discovery documents, dynamic registration, PKCE rejection, token and refresh grants, forged-token rejection) and the MCP protocol (initialize, notifications, tool listing, growth-delta arithmetic, tool error paths). The Telegram API is mocked; no network access and no real bot token are needed.

The suite runs against the deployed source itself — tests/build.mjs rewrites exactly one line, the Val Town blob import, and changes nothing else.

License

MIT

推荐服务器

Baidu Map

Baidu Map

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

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

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

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

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

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

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

官方
精选
本地
TypeScript
VeyraX

VeyraX

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

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

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

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

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

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

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

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选