Sponsored by Deepsite.site

Telegram Notification MCP Server

Created By
kstonekuan6 months ago
Simple MCP server to send you notifications on telegram
Content

Telegram Notification MCP Server

Telegram MCP Logo

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.

Features

  • 🤖 MCP Tool: Provides a send_telegram_message tool 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

  1. Telegram Bot: Create a bot via @BotFather and get your bot token
  2. Chat ID: Get your chat ID by sending a message to your bot and visiting:
    https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
    
  3. Cloudflare Account: Sign up at cloudflare.com

Installation

  1. Clone this repository
  2. Install dependencies:
    pnpm install
    

Configuration

  1. 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.

  2. 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.

  3. Update wrangler.toml with 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 send
  • chat_id (optional): Telegram chat ID (uses DEFAULT_CHAT_ID if not provided)
  • parse_mode (optional): "Markdown" or "HTML" for message formatting
  • disable_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

Telegram Notification Example

Example of Telegram notifications from Claude Code

Claude Code Integration Example

Claude Code sending notifications during task completion

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:

  1. pnpm format - Format code with Biome
  2. pnpm lint:fix - Fix linting issues
  3. pnpm cf-typegen - Generate Cloudflare types
  4. pnpm 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

  1. Connection closes immediately: Check that your worker is running and accessible at the specified URL.

  2. No endpoint event received: Ensure the SSE headers are being sent correctly and the stream is properly formatted.

  3. Telegram notifications not sent: Verify your BOT_TOKEN and DEFAULT_CHAT_ID are 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:

License

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Playwright McpPlaywright MCP server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
DeepChatYour AI Partner on Desktop
WindsurfThe new purpose-built IDE to harness magic
Amap Maps高德地图官方 MCP Server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
ChatWiseThe second fastest AI chatbot™
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Tavily Mcp
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Serper MCP ServerA Serper MCP Server
CursorThe AI Code Editor