Telegram Notification MCP Server
Telegram Notification MCP Server
一个 MCP(模型上下文协议)服务器,当 Claude Code 完成任务时向 Telegram 发送通知。使用 TypeScript 和 Cloudflare Agents SDK 构建,可部署在 Cloudflare Workers 上。
📢 更喜欢 Discord? 请查看 Discord Notification MCP 以获取 Discord 通知。
功能
🤖 MCP 工具:提供一个
send_telegram_message工具用于发送通知🚀 Cloudflare Workers:以无服务器方式运行,全球分布
🔐 认证:需要存储在 Cloudflare secret 中的 bearer token
🌐 流式 HTTP:使用当前无状态的 MCP 传输
💬 消息格式化:支持 Markdown 和 HTML 格式化
📝 格式化:支持 Markdown 和 HTML 消息格式化
Related MCP server: mcp-telegram-claudecode
架构
此服务器使用 Cloudflare 的 Agents SDK 实现 MCP 规范:
POST /mcp:用于 MCP 通信的无状态流式 HTTP 端点
GET /sse:返回
410 Gone;旧版 SSE 客户端必须迁移到/mcp使用 TypeScript、MCP SDK 和 Cloudflare Agents SDK 构建
正确的 JSON-RPC 2.0 错误处理
已启用 Node.js 兼容模式
设置
前提条件
Telegram 机器人:通过 @BotFather 创建机器人并获取你的机器人令牌
聊天 ID:向你的机器人发送消息并访问以下地址获取聊天 ID:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdatesCloudflare 账户:在 cloudflare.com 注册
安装
克隆此仓库
安装依赖:
pnpm install
配置
从示例创建
.dev.vars文件:cp .dev.vars.example .dev.vars然后使用你的机器人令牌和聊天 ID 编辑
.dev.vars。此文件用于本地开发和部署。对于生产部署,生成 MCP bearer token 并设置 Cloudflare secrets:
openssl rand -hex 32 pnpm exec wrangler secret put BOT_TOKEN pnpm exec wrangler secret put DEFAULT_CHAT_ID # Optional pnpm exec wrangler secret put MCP_AUTH_TOKEN注意:DEFAULT_CHAT_ID 是可选的。如果未设置,则在调用
send_telegram_message工具时必须提供chat_id参数。如果需要,更新
wrangler.toml中的 worker 名称
部署
部署到 Cloudflare Workers:
使用 Wrangler 部署:
# First set secrets
pnpm exec wrangler secret put BOT_TOKEN
pnpm exec wrangler secret put DEFAULT_CHAT_ID # Optional
# Then deploy
pnpm run deploy替代方案:持续部署
你也可以直接从 cloudflare 仪表板设置持续部署。了解更多关于 git 与 cloudflare 集成 的信息
Claude Code 配置
使用流式 HTTP 和相同的 bearer token 将 MCP 服务器添加到 Claude Code:
# For production deployment
claude mcp add --scope user --transport http \
--header "Authorization: Bearer <MCP_AUTH_TOKEN>" \
telegram-notify https://your-worker-name.workers.dev/mcp
# For local development
claude mcp add --transport http \
--header "Authorization: Bearer <MCP_AUTH_TOKEN>" \
telegram-notify http://localhost:8787/mcp该令牌是客户端访问 MCP 端点的令牌,而不是 Telegram 机器人令牌。切勿将机器人令牌放入 Claude 的 MCP 配置中。
你可以使用以下命令验证配置:
claude mcp list使用
配置完成后,Claude Code 可以在你需要时向你的 Telegram 发送通知。
可用工具
send_telegram_message:向 Telegram 发送通知消息
text(必填):要发送的消息文本chat_id(可选):Telegram 聊天 ID(如果未提供,则使用 DEFAULT_CHAT_ID)parse_mode(可选):用于消息格式化的 "Markdown" 或 "HTML"disable_notification(可选):静默发送消息
示例用法:
// Uses DEFAULT_CHAT_ID from environment
await send_telegram_message({ text: "Task completed!" })
// Send to specific chat (overrides DEFAULT_CHAT_ID)
await send_telegram_message({ text: "Hello!", chat_id: "123456789" })
// Send with Markdown formatting
await send_telegram_message({
text: "*Bold* and _italic_ text",
parse_mode: "Markdown"
})何时会收到通知
Claude Code 在以下情况下发送通知:
你明确要求:“完成时通知我”或“在 Telegram 上告诉我”
执行过程中发生错误
达到重要里程碑
需要用户输入或干预
示例场景
# You say: "Deploy to production and notify me when done"
# Result: 🤖 Claude Code Notification
# Deployment completed successfully! The app is now live.
# You say: "Run all tests and let me know the results"
# Result: 🤖 Claude Code Notification
# All tests passed! 52/52 tests successful.
# You say: "Process this data and notify me if there are any errors"
# Result: 🤖 Claude Code Notification
# Error: Failed to process row 451 - invalid date format示例通知
CLAUDE.md 示例
为了鼓励 Claude Code 有效使用 Telegram 通知,请将这些添加到你的 CLAUDE.md:
# Telegram Notifications
Use the mcp__telegram-notify__send_telegram_message tool to send notifications to Telegram.
- Always send a Telegram notification when:
- A task is fully complete
- You need user input to continue
- An error occurs that requires user attention
- The user explicitly asks for a notification (e.g., "notify me", "send me a message", "let me know")
- Include relevant details in notifications:
- For builds/tests: success/failure status and counts
- For errors: the specific error message and file location
- Use concise, informative messages like:
- "✅ Build completed successfully (2m 34s)"
- "❌ Tests failed: 3/52 failing in auth.test.ts"
- "⚠️ Need permission to modify /etc/hosts"开发
本地运行:
# Start local development server
pnpm dev对于本地开发,Wrangler 将自动从你的 .dev.vars 文件加载环境变量。
部署前运行所有检查:
pnpm build此命令运行:
pnpm format- 使用 Biome 格式化代码pnpm lint:fix- 修复 lint 问题pnpm cf-typegen- 生成 Cloudflare 类型pnpm type-check- 检查 TypeScript 类型
测试服务器:
# An unauthenticated request must return HTTP 401
curl -i http://localhost:8787/mcp
# Claude Code performs the authenticated MCP handshake and health check
claude mcp list调试
测试认证
你可以验证端点是否拒绝没有 bearer token 的请求:
curl -i http://localhost:8787/mcp这应返回 401 Unauthorized。然后使用 claude mcp list 验证已认证的客户端连接。
常见问题
401 Unauthorized:确认客户端的
Authorization: Bearer ...头与MCP_AUTH_TOKENCloudflare secret 匹配。MCP 重连或超时:确认客户端使用 HTTP 传输和
/mcp端点,而不是已弃用的/sse端点。Telegram 通知未发送:验证你的
BOT_TOKEN和DEFAULT_CHAT_ID在 Worker 环境中是否正确设置。
技术细节
语言:TypeScript(ES2021 目标)
运行时:Cloudflare Workers,支持 Node.js 兼容性
协议:MCP(模型上下文协议)
传输:无状态流式 HTTP
可观测性:已启用用于监控
参考
本项目基于以下指南构建:
许可证
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables Claude Code to send notifications to Discord channels via webhooks when tasks complete, errors occur, or user intervention is needed. Deployed serverlessly on Cloudflare Workers with support for rich message formatting and embeds.8MIT
- AlicenseAqualityDmaintenanceEnables Claude Code to send and receive messages via Telegram for remote interaction and approval of sensitive operations.8187MIT
- FlicenseNot gradedqualityDmaintenanceSends Telegram alerts for Claude Code status updates, including notifications for task completion, user requests, and custom status updates with normal or urgent priority.1
- FlicenseNot gradedqualityDmaintenanceEnables Claude Code to send messages to and receive instructions from Telegram, with task tracking and persistent storage.
Related MCP Connectors
Telegram bridge for your MCP-compatible agent. Bidirectional, no LLM in our stack.
Multi-tenant Telegram gateway for AI agents — HTTP+stdio, 8 tools, MTProto User API
Let your AI agent notify you by email, Slack, Discord, or webhook. One tool: send_notification.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kstonekuan/telegram-notification-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server