Telegram Notification MCP Server
Enables Claude Code to send Telegram notifications when tasks complete, errors occur, or user intervention is needed. Runs serverless on Cloudflare Workers with support for formatted messages and flexible chat targeting.
README
Telegram Notification MCP Server
<div align="center"> <img src="./images/logo.png" alt="Telegram MCP Logo" width="200">
An MCP (Model Context Protocol) server that sends notifications to Telegram when Claude Code completes tasks. Built with TypeScript using the Cloudflare Agents SDK and deployable on Cloudflare Workers. </div>
Features
- 🤖 MCP Tool: Provides a
send_telegram_messagetool for sending notifications - 🚀 Cloudflare Workers: Runs serverless with global distribution
- 🔐 Secure: Uses Cloudflare secrets for credentials
- 🌐 Dual Transport: Supports both SSE and Streamable HTTP for maximum compatibility
- 💾 Durable Objects: State management required by McpAgent
- 💬 Message Formatting: Supports Markdown and HTML formatting
- 📝 Formatting: Supports Markdown and HTML message formatting
Architecture
This server implements the MCP specification using Cloudflare's Agents SDK:
- GET /sse: SSE endpoint for MCP communication
- POST /mcp: Streamable HTTP endpoint for MCP communication
- Built with TypeScript, MCP SDK, and Cloudflare Agents SDK
- Proper JSON-RPC 2.0 error handling
- Durable Objects for stateful connections (required by McpAgent)
- Node.js compatibility mode enabled
Setup
Prerequisites
- Telegram Bot: Create a bot via @BotFather and get your bot token
- Chat ID: Get your chat ID by sending a message to your bot and visiting:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Cloudflare Account: Sign up at cloudflare.com
Installation
- Clone this repository
- Install dependencies:
pnpm install
Configuration
-
Create a
.dev.varsfile from the example:cp .dev.vars.example .dev.varsThen edit
.dev.varswith your bot token and chat ID. This file is used for both local development and deployment. -
For production deployment, set up Cloudflare secrets:
npx wrangler secret put BOT_TOKEN npx wrangler secret put DEFAULT_CHAT_ID # OptionalNote: The DEFAULT_CHAT_ID is optional. If not set, you must provide a chat_id parameter when calling the
send_telegram_messagetool. -
Update
wrangler.tomlwith your worker name if desired
Deployment
Deploy to Cloudflare Workers:
Deploy using Wrangler:
# First set secrets
npx wrangler secret put BOT_TOKEN
npx wrangler secret put DEFAULT_CHAT_ID # Optional
# Then deploy
pnpm run deploy
Alternative: Continuous Deployment
You can also set up continuous deployment directly from the cloudflare dashboard. Learn more about git integration with cloudflare
Claude Code Configuration
Add the MCP server to Claude Code using the CLI via SSE transport:
# For production deployment (SSE)
claude mcp add telegram-notify https://your-worker-name.workers.dev/sse -t sse
# For local development
claude mcp add telegram-notify http://localhost:8787/sse -t sse
Note: This server supports both SSE (Server-Sent Events) and Streamable HTTP transport. While SSE works well, Streamable HTTP provides better reliability and is the newer standard.
You can verify the configuration with:
claude mcp list
Usage
Once configured, Claude Code can send notifications to your Telegram whenever you need them.
Available Tool
send_telegram_message: Send a notification message to Telegram
text(required): The message text to sendchat_id(optional): Telegram chat ID (uses DEFAULT_CHAT_ID if not provided)parse_mode(optional): "Markdown" or "HTML" for message formattingdisable_notification(optional): Send message silently
Example usage:
// 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"
})
When You'll Get Notifications
Claude Code sends notifications when:
- You explicitly ask: "notify me when done" or "let me know on Telegram"
- Errors occur during execution
- Important milestones are reached
- User input or intervention is needed
Example Scenarios
# 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
Example Notifications
<div align="center"> <img src="./images/telegram.jpg" alt="Telegram Notification Example" width="600"> <p><em>Example of Telegram notifications from Claude Code</em></p> </div>
<div align="center"> <img src="./images/claude_code.png" alt="Claude Code Integration Example" width="600"> <p><em>Claude Code sending notifications during task completion</em></p> </div>
CLAUDE.md Examples
To encourage Claude Code to use Telegram notifications effectively, add these to your 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"
Development
Run locally:
# Start local development server
pnpm dev
For local development, Wrangler will automatically load environment variables from your .dev.vars file.
Run all checks before deployment:
pnpm build
This command runs:
pnpm format- Format code with Biomepnpm lint:fix- Fix linting issuespnpm cf-typegen- Generate Cloudflare typespnpm type-check- Check TypeScript types
Test the server:
# Test SSE connection
curl http://localhost:8787/sse
# Test health endpoint
curl http://localhost:8787/
Debugging
Testing the SSE Connection
You can test the SSE endpoint directly:
curl -N http://localhost:8787/sse
This should return an event stream starting with an endpoint event.
Common Issues
-
Connection closes immediately: Check that your worker is running and accessible at the specified URL.
-
No endpoint event received: Ensure the SSE headers are being sent correctly and the stream is properly formatted.
-
Telegram notifications not sent: Verify your
BOT_TOKENandDEFAULT_CHAT_IDare correctly set in the worker environment.
Technical Details
- Language: TypeScript (ES2021 target)
- Runtime: Cloudflare Workers with Node.js compatibility
- Protocol: MCP (Model Context Protocol)
- Transport: SSE and Streamable HTTP
- State Management: Durable Objects (required by McpAgent)
- Observability: Enabled for monitoring
References
This project was built following these guides:
- Build a Remote MCP server - Cloudflare Agents
- Model Context Protocol (MCP) - Cloudflare Agents
- MCP Transport Methods - Cloudflare Agents
- Cloudflare MCP Template (remote-mcp-authless)
Related Projects
- Discord Notification MCP - Send notifications to Discord instead of Telegram
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。