mcp-telegram-agent

mcp-telegram-agent

Sends Telegram notifications and supports onboarding, updates, and control replies via MCP tools from any AI agent.

Category
访问服务器

README

🤖 If you are an AI agent: read AGENTS.md first, then AGENT_SETUP.md.

🤖 MCP Telegram Agent

Send Telegram notifications directly from any MCP-compatible AI agent.

This project is a TypeScript MCP server over stdio, designed to be easy to run locally and easy to distribute via npm + npx.

✨ Features

  • ✅ Send a message to Telegram with one MCP tool call
  • ✅ Guided onboarding flow: token → setup code verification → auto config snippet
  • ✅ Validate Telegram config before sending anything
  • ✅ Read recent Telegram updates to discover chat_id and message_id
  • ✅ Works with npx mcp-telegram-agent in MCP config
  • ✅ Token-first setup (safer than hardcoding full API URL)

📦 Installation

Option A: Use directly with npx (recommended for MCP clients)

No local clone required in production:

npx -y mcp-telegram-agent

Option B: Local development

npm install
npm run check
npm run build
npm run dev

🔧 Environment Variables

Recommended (default behavior)

  • BOT_TELEGRAM_TOKEN (required)
  • BOT_TELEGRAM_CHAT_ID (required)

Compatibility aliases

  • BOT_TELEGRAM_ID (alias for chat ID)
  • BOT_TELEGRAM_URL (legacy fallback, full sendMessage URL)

Optional

  • BOT_TELEGRAM_TIMEOUT_MS (default: 10000)
  • BOT_TELEGRAM_THREAD_ID (for Telegram forum topics)
  • BOT_TELEGRAM_API_BASE_URL (advanced/testing override, default: https://api.telegram.org)

Security note: Prefer BOT_TELEGRAM_TOKEN over BOT_TELEGRAM_URL so your secret is managed as a single token value.

🧠 MCP Client Configuration

npx setup (recommended)

{
  "mcpServers": {
    "telegram-agent": {
      "command": "npx",
      "args": ["-y", "mcp-telegram-agent"],
      "env": {
        "BOT_TELEGRAM_TOKEN": "123456789:AAxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "BOT_TELEGRAM_CHAT_ID": "123456789"
      }
    }
  }
}

Local build setup

{
  "mcpServers": {
    "telegram-agent": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/mcp_telegram_agent/dist/index.js"],
      "env": {
        "BOT_TELEGRAM_TOKEN": "123456789:AAxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "BOT_TELEGRAM_CHAT_ID": "123456789"
      }
    }
  }
}

🛠️ Exposed MCP Tools

telegram_onboarding_prepare

Prepares onboarding for a fresh token and returns:

  • a setup code
  • exact message to send (plain setup code)
  • MCP config template
  • if botToken is omitted and client supports elicitation, MCP requests secure token input UI

telegram_onboarding_verify

Verifies onboarding by scanning updates for the setup code (plain message, or /start <code>) and then:

  • discovers chat_id + message_id
  • builds a ready-to-paste MCP config JSON
  • optionally sends a test message automatically
  • supports cautious mode with explicit chat_id confirmation (requireChatIdConfirmation + expectedChatId)
  • if botToken is omitted and client supports elicitation, MCP requests secure token input UI

send_telegram_notification

Send a message to your configured Telegram chat.

Input:

  • message (string, required)
  • parseMode (HTML | Markdown | MarkdownV2, optional)
  • disableNotification (boolean, optional)

Output example:

  • Notification sent to Telegram (status 200, message_id=207).

telegram_config_status

Validate env config and show active source (BOT_TELEGRAM_TOKEN vs BOT_TELEGRAM_URL).

telegram_get_updates

Fetch recent updates from Telegram to inspect:

  • chat_id
  • message_id
  • message text
  • username

Useful when you are still wiring your bot and need IDs.

Supports incremental polling:

  • fromUpdateId (fetch newer updates only)
  • waitSeconds (Telegram long polling timeout)

telegram_send_control_checkpoint

Sends a structured checkpoint message (title + summary + control metadata) so users can reply with control actions.

Typical usage:

  • agent says "task done"
  • user replies to that checkpoint with continue CODE123, stop CODE123, etc.

telegram_poll_control_replies

Reads new updates and filters control replies by:

  • replyToMessageId
  • controlCode
  • instanceId
  • optional actionFilter

This is designed for multi-IDE safety and uses long polling (waitSeconds) to reduce API churn.

telegram_ack_control_reply

Sends an acknowledgement as a direct reply to the user control message, including status and summary.

🧭 Agent Command (/setup-mcp-telegram-agent)

This repository ships:

  • AGENTS.md
  • AGENT_SETUP.md
  • .cursor/commands/setup-mcp-telegram-agent.md

Suggested chat command:

/setup-mcp-telegram-agent

Expected flow:

  1. Install/activate MCP first with npx -y mcp-telegram-agent (no token required yet)
  2. Ask for bot token (or direct user to create one at https://telegram.me/BotFather#)
  3. Run telegram_onboarding_prepare
  4. Ask user to send <code> (plain message) to the bot
  5. Run telegram_onboarding_verify in confirmation mode to list candidates
  6. Ask user to confirm exact chat_id
  7. Run telegram_onboarding_verify again with expectedChatId
  8. Apply generated MCP config
  9. Send one test notification

📲 Telegram Bot Setup (BotFather)

1) Open BotFather

Search for @BotFather in Telegram and open it.

BotFather setup example

2) Create a new bot

Send:

/newbot

Then follow prompts:

  1. Bot display name (example: My MCP Notifier)
  2. Bot username ending in bot (example: my_mcp_notifier_bot)

BotFather returns your token:

123456789:AAxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Save it securely as BOT_TELEGRAM_TOKEN.

3) Start a chat with your bot

Open your new bot and click Start (or send any message).

4) Get your chat_id and message_id

Call:

curl "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates"

Then look for:

  • message.chat.id → this is your chat_id
  • message.message_id → this is the message ID

Visual guide:

Get chat id and message id

🧪 Quick Test

Use your real values:

curl -sS -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage" \
  -H "Content-Type: application/json" \
  -d '{"chat_id":"<YOUR_CHAT_ID>","text":"✅ MCP test message"}'

🚀 Publish to npm

Publishing is automated with GitHub Actions + semantic-release.

After the first release, users can run:

npx -y mcp-telegram-agent

⚙️ GitHub Actions Auto Publish

This repository includes:

  • .github/workflows/release.yml
  • .releaserc.json

Behavior:

  1. Runs on each push to main
  2. Uses Conventional Commits to decide release type (fix = patch, feat = minor, BREAKING CHANGE = major)
  3. Creates GitHub release + publishes to npm

Required GitHub secret:

  • NPM_TOKEN (npm automation token with publish permissions)

Required commit style examples:

fix: first automated release setup
feat: add support for telegram topics

First release target (v0.0.1):

  1. Create and push baseline tag v0.0.0 once.
  2. Push a fix: commit to main.
  3. Action will publish v0.0.1.

Commands:

git tag v0.0.0
git push origin v0.0.0
git commit --allow-empty -m "fix: bootstrap first semantic release"
git push origin main

🧩 GitHub Repository Setup

If this is a fresh local directory:

git init
git add .
git commit -m "Initial MCP telegram agent server"
git branch -M main
git remote add origin https://github.com/tecnomanu/mcp-telegram-agent.git
git push -u origin main

⚠️ Troubleshooting

  • chat not found:
    • Ensure you started chat with the bot first.
    • Re-check BOT_TELEGRAM_CHAT_ID from getUpdates.
  • 401 Unauthorized:
    • Token is invalid, regenerated, or malformed.
  • No updates in getUpdates:
    • Send a message to your bot, then retry.

📄 License

MIT

推荐服务器

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 服务器

官方
精选