Telegram通知
HTTP-SSE发送Telegram通知的MCP服务器
发送Telegram通知的MCP服务器
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.
send_telegram_message tool for sending notificationsThis server implements the MCP specification using Cloudflare's Agents SDK:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
pnpm install
Create a .dev.vars file from the example:
cp .dev.vars.example .dev.vars
Then edit .dev.vars with 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 # Optional
Note: The DEFAULT_CHAT_ID is optional. If not set, you must provide a chat_id parameter when calling the send_telegram_message tool.
Update wrangler.toml with your worker name if desired
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
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
Once configured, Claude Code can send notifications to your Telegram whenever you need them.
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 silentlyExample 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" })
Claude Code sends notifications when:
# 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 of Telegram notifications from Claude Code
  Claude Code sending notifications during task completion
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"
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 typesTest the server:
# Test SSE connection curl http://localhost:8787/sse # Test health endpoint curl http://localhost:8787/
You can test the SSE endpoint directly:
curl -N http://localhost:8787/sse
This should return an event stream starting with an endpoint event.
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_TOKEN and DEFAULT_CHAT_ID are correctly set in the worker environment.
This project was built following these guides:
MIT