telegram-mcp
Allows AI agents to send messages, photos, documents, polls, progress updates, and receive user responses via Telegram, enabling bidirectional communication and workflow automation.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@telegram-mcpSend a status update to the dev team about the build progress."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
telegram-mcp 🤖✉️
MCP (Model Context Protocol) server for Telegram Bot API integration.
Enables AI agents to send messages, photos, documents, polls, progress updates, and receive user responses via Telegram — all with persistent storage, rate limiting, and robust error handling.
Features
✅ 10 MCP Tools — send_message, send_photo, send_document, send_progress, send_todo_update, send_error_alert, ask_user, wait_for_response, create_poll, send_daily_report
✅ Bidirectional Communication — AI agents can pause, ask questions, wait for Telegram replies, and resume workflows based on user responses
✅ Multi-Chat Support — Configure one or many Telegram chats/groups/channels
✅ MarkdownV2 Formatting — Rich text with bold, italic, code blocks, links, tables, progress bars
✅ SQLite Persistence — Conversation history, pending response tracking, message logs
✅ Rate Limiting — Token-bucket algorithm respects Telegram's API limits
✅ Retry with Exponential Backoff — Auto-retries failed API calls
✅ Comprehensive Logging — Structured logs with levels (debug/info/warn/error)
✅ Type-Safe — Full TypeScript with Zod schemas for all tool inputs
✅ Docker Support — Multi-stage Dockerfile + docker-compose
✅ Environment Config — All settings via environment variables with
.env.example✅ Polling-Based Updates — No webhook needed; polls Telegram for new messages
Related MCP server: mcp-telegram
Architecture
┌─────────────────┐ stdio ┌──────────────────────────┐
│ AI Agent / │ ◄──────────► │ telegram-mcp │
│ MCP Client │ │ │
└─────────────────┘ │ ┌───────────────────┐ │
│ │ MCP Tools Layer │ │
│ │ (Zod schemas) │ │
│ └────────┬──────────┘ │
│ │ │
│ ┌────────▼──────────┐ │
│ │ Telegram Client │ │
│ │ (retry + rate │ │
│ │ limiting) │ │
│ └────────┬──────────┘ │
│ │ │
│ ┌────────▼──────────┐ │
│ │ Update Poller │ │
│ │ (getUpdates loop) │ │
│ └────────┬──────────┘ │
│ │ │
│ ┌────────▼──────────┐ │
│ │ SQLite Storage │ │
│ │ (better-sqlite3) │ │
│ └───────────────────┘ │
└──────────────────────────┘
│
Telegram Bot API
│
Telegram
(Users/Chats)Prerequisites
Node.js ≥ 22 (or Docker)
A Telegram Bot Token from @BotFather
The Chat ID of your target Telegram chat(s) (use @userinfobot to find)
Installation
Option 1: npm / pnpm (standalone)
# Clone or create the project directory
cd telegram-mcp
# Install dependencies
npm install
# Build TypeScript
npm run build
# Copy and edit environment file
cp .env.example .env
# Edit .env with your BOT_TOKEN and CHAT_IDOption 2: Docker
# Build the image
docker build -t telegram-mcp .
# Or use docker-compose
cp .env.example .env
# Edit .env with your BOT_TOKEN and CHAT_ID
docker compose up -dConfiguration
All configuration is via environment variables (defined in .env):
Variable | Required | Default | Description |
| ✅ | — | Telegram Bot API token from @BotFather |
| ✅ | — | Comma-separated chat IDs (e.g., |
| ❌ | — | Bot owner's Telegram user ID |
| ❌ |
| SQLite database file path |
| ❌ |
| Log level: |
| ❌ |
| Polling interval for message updates (ms) |
| ❌ |
| Default timeout for |
| ❌ |
| Poll interval when waiting for a response (ms) |
| ❌ |
| Telegram API rate limit (requests per second) |
| ❌ |
| Maximum retries for failed API calls |
Usage
Running the Server
# Development mode (with hot reload)
npm run dev
# Production mode
npm start
# With Docker
docker compose upThe server starts an MCP service over stdio, which is automatically used by MCP-compatible clients.
Configure your AI agent or MCP client to launch:
node /path/to/telegram-mcp/dist/index.jsMCP Client Configuration
If using Claude Desktop or another MCP client, add to your claude_desktop_config.json:
{
"mcpServers": {
"telegram": {
"command": "node",
"args": ["/absolute/path/to/telegram-mcp/dist/index.js"],
"env": {
"BOT_TOKEN": "your_bot_token",
"CHAT_ID": "your_chat_id"
}
}
}
}Tools
send_message
Send a text message to one or all configured chats.
Parameter | Type | Required | Description |
| string | ✅ | Message content (MarkdownV2) |
| string | ❌ | Specific chat ID; omit to broadcast |
| enum | ❌ |
|
| boolean | ❌ | Disable link previews |
| boolean | ❌ | Send silently |
send_photo
Send a photo (by URL or Telegram file_id).
Parameter | Type | Required | Description |
| string | ✅ | URL or file_id |
| string | ❌ | Optional caption |
| string | ❌ | Specific chat ID |
| enum | ❌ |
|
send_document
Send a document (by URL or file_id).
Parameter | Type | Required | Description |
| string | ✅ | URL or file_id |
| string | ❌ | Optional caption |
| string | ❌ | Specific chat ID |
| string | ❌ | Display name |
send_progress
Send a visual progress bar.
Parameter | Type | Required | Description |
| string | ✅ | Progress title |
| number | ✅ | Current value |
| number | ✅ | Total value |
| string | ❌ | Optional status |
| string | ❌ | Specific chat ID |
send_todo_update
Notify about a todo item status change.
Parameter | Type | Required | Description |
| enum | ✅ |
|
| string | ✅ | Todo title |
| string | ❌ | Optional description |
| string | ❌ | e.g., |
| enum | ❌ |
|
| string | ❌ | Specific chat ID |
send_error_alert
Send a structured error notification.
Parameter | Type | Required | Description |
| string | ✅ | Error title |
| string | ✅ | Error details |
| string | ❌ | Stack trace |
| object | ❌ | Key-value pairs |
| string | ❌ | Specific chat ID |
create_poll
Create and send a poll.
Parameter | Type | Required | Description |
| string | ✅ | Poll question |
| string[] | ✅ | 2–10 options |
| boolean | ❌ | Default: true |
| boolean | ❌ | Default: false |
| enum | ❌ |
|
| number | ❌ | For quiz polls |
| string | ❌ | For quiz polls |
| number | ❌ | Auto-close seconds |
| string | ❌ | Specific chat ID |
send_daily_report
Send a structured daily summary.
Parameter | Type | Required | Description |
| string | ❌ | ISO date (defaults to today) |
| string | ✅ | Report title |
| array | ✅ |
|
| string | ❌ | Optional footer |
| string | ❌ | Specific chat ID |
ask_user
Send a question and create a pending response slot. Returns a response_id.
Parameter | Type | Required | Description |
| string | ✅ | Question text |
| string | ❌ | Specific chat ID |
| number | ❌ | Override default timeout |
Returns: response_id string (pass to wait_for_response)
wait_for_response
Block until the user replies to a previously asked question.
Parameter | Type | Required | Description |
| string | ✅ | ID from |
| number | ❌ | Timeout override |
| string | ❌ | Narrow chat scope |
Returns:
{
"received": true,
"text": "User's reply message",
"messageId": 42
}On timeout:
{
"received": false,
"error": "Timeout: No response received within the allowed time."
}Two-Phase Agent Workflow (ask → wait → resume)
The most powerful feature is the ability for an AI agent to pause execution, ask a question via Telegram, wait for the user's reply, and resume the workflow based on the response.
Flow
Agent telegram-mcp Telegram User
│ │ │
│── ask_user({question}) ──►─────────── message ────►│
│◀── { response_id } ──────│ │
│ │ │
│── wait_for_response({ │ │
│ response_id }) ──────► │
│ │ │
│ │◄──── reply ────────────│
│◀── { received:true, │ │
│ text:"..." } ──────│ │
│ │ │
│ (resumes logic based │ │
│ on user's response) │ │Example Agent Script
// Phase 1: Ask the user
const { response_id } = await mcp.callTool("ask_user", {
question: "Which report should I generate? (daily/weekly/monthly)"
});
// Phase 2: Wait for their response (blocks up to 5 minutes)
const result = await mcp.callTool("wait_for_response", {
response_id: response_id,
timeout_seconds: 300
});
if (result.received) {
const userChoice = result.text.toLowerCase();
if (userChoice.includes("daily")) {
await generateDailyReport();
} else if (userChoice.includes("weekly")) {
await generateWeeklyReport();
}
await mcp.callTool("send_message", {
text: `✅ Generating ${userChoice} report...`
});
} else {
await mcp.callTool("send_error_alert", {
title: "No Response",
description: "User did not respond within the timeout period."
});
}Development
# Install dependencies
npm install
# Run in development mode (with hot reload)
npm run dev
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Build for production
npm run build
# Lint (if configured)
npm run lintProject Structure
telegram-mcp/
├── src/
│ ├── index.ts # Entry point — starts MCP server + polling
│ ├── config.ts # Environment variable validation (Zod)
│ ├── logger.ts # Structured logging
│ ├── types.ts # TypeScript interfaces
│ ├── telegram/
│ │ ├── client.ts # Telegram Bot API client (retry, rate limit)
│ │ └── formatter.ts # MarkdownV2 formatting utilities
│ ├── storage/
│ │ └── db.ts # SQLite database (conversations, pending)
│ ├── handlers/
│ │ └── updates.ts # Telegram update polling
│ └── mcp/
│ └── tools.ts # All MCP tool definitions + response handler
├── tests/
│ └── telegram-mcp.test.ts # Vitest unit tests
├── Dockerfile # Multi-stage Docker build
├── docker-compose.yml # Docker Compose setup
├── .env.example # Environment template
├── vitest.config.ts # Test configuration
├── tsconfig.json # TypeScript configuration
└── package.jsonTesting
npm testTests cover:
MarkdownV2 escaping and formatting
Structured message builders (errors, todos, reports, polls)
Database CRUD operations (in-memory SQLite)
Config validation logic
Response ID generation
Error Handling & Reliability
Exponential backoff — Failed Telegram API calls retry with
1s → 2s → 4sdelays (configurable)Rate limiting — Token-bucket algorithm prevents hitting Telegram's rate limits
Graceful shutdown — Cleanly closes database and stops polling on SIGINT/SIGTERM
Uncaught exception handling — Logs fatal errors before exiting
Input validation — All tool inputs validated with Zod schemas
Database
The server uses SQLite (via better-sqlite3) for persistence:
conversations — Full chat history (user + agent messages)
pending_responses — Active
ask_user/wait_for_responserequestsmessages_log — Auditable log of all sent/received messages
The database file is stored at DB_PATH (default: ./data/telegram-mcp.db).
Docker
Build & Run
# Build
docker build -t telegram-mcp .
# Run with .env file
docker run --env-file .env -v telegram-mcp-data:/app/data telegram-mcp
# Or use docker-compose
docker compose up -dMulti-Stage Build
The Dockerfile uses a multi-stage build:
Builder stage — Installs dev dependencies, compiles TypeScript
Production stage — Minimal image with only runtime dependencies
Security
Bot Token — Keep your
BOT_TOKENsecret. Never commit it to version control.Chat IDs — Restrict which chats the bot listens to via
CHAT_ID.Input Validation — All tool inputs are validated with Zod schemas.
No Webhooks — Uses polling instead, avoiding the need for a public HTTPS endpoint.
License
MIT
Contributing
Contributions are welcome! Please open an issue or PR for:
Additional Telegram API features
Improved formatting utilities
Enhanced response matching (e.g., reply chains)
Webhook support
Multi-language support
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.
Latest Blog Posts
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/Abol1644/telegram-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server