mcp-telegram

IQAIcom/mcp-telegram

3.3

If you are the rightful owner of mcp-telegram and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

An MCP server for interacting with Telegram bots and channels using the Telegraf library.

Tools
5
Resources
0
Prompts
0

Telegram MCP Server

npm version License: MIT

Overview

An MCP (Model Context Protocol) server for interacting with Telegram bots and channels using the Telegraf library. This server enables AI agents to send messages, manage channels, forward content, and respond intelligently to Telegram conversations.

By implementing the Model Context Protocol (MCP), this server allows Large Language Models (LLMs) to interact with Telegram directly through their context window, bridging the gap between AI and messaging platforms.

Features

Core Tools

  • SEND_MESSAGE: Send messages to channels or chats with optional topic support
  • GET_CHANNEL_INFO: Get information about channels/chats
  • FORWARD_MESSAGE: Forward messages between chats
  • PIN_MESSAGE: Pin messages in channels
  • GET_CHANNEL_MEMBERS: Get list of channel administrators

AI Sampling (Enhanced)

  • Intelligent Responses: AI-powered responses using FastMCP sampling
  • Mention-Only Mode: Smart filtering - responds when mentioned in groups
  • Multi-Message Types: Supports text, photos, documents, voice, video, stickers, locations, contacts, polls
  • Access Control: Configurable user/chat allow/block lists
  • Rate Limiting: Per-user and per-chat rate limiting
  • Advanced Configuration: Highly customizable behavior and templates

Installation

Using npx (Recommended)

To use this server without installing it globally:

npx @iqai/mcp-telegram

Build from Source

git clone https://github.com/IQAIcom/mcp-telegram.git
cd mcp-telegram
pnpm install
pnpm run build

Running with an MCP Client

Add the following configuration to your MCP client settings (e.g., claude_desktop_config.json).

Minimal Configuration

{
  "mcpServers": {
    "telegram": {
      "command": "npx",
      "args": ["-y", "@iqai/mcp-telegram"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "your_bot_token_here"
      }
    }
  }
}

Advanced Configuration (Local Build)

{
  "mcpServers": {
    "telegram": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-telegram/dist/index.js"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "your_bot_token_here",
        "SAMPLING_ENABLED": "true",
        "SAMPLING_MENTION_ONLY": "true"
      }
    }
  }
}

Configuration (Environment Variables)

Required

VariableRequiredDescription
TELEGRAM_BOT_TOKENYesYour Telegram bot token from @BotFather

Sampling Configuration

VariableDefaultDescription
SAMPLING_ENABLEDtrueEnable/disable AI sampling entirely
SAMPLING_MENTION_ONLYtrueOnly respond when mentioned in groups
SAMPLING_RESPOND_TO_DMStrueAlways respond in DMs
SAMPLING_MAX_TOKENS1000Max tokens per AI response
SAMPLING_SHOW_TYPINGtrueShow typing indicator
SAMPLING_SILENT_MODEfalseLog but don't respond

Access Control

VariableDefaultDescription
SAMPLING_ALLOWED_CHATS""Comma-separated chat IDs/usernames to allow (empty = all)
SAMPLING_BLOCKED_CHATS""Comma-separated chat IDs/usernames to ignore
SAMPLING_ALLOWED_USERS""Comma-separated user IDs to allow (empty = all)
SAMPLING_BLOCKED_USERS""Comma-separated user IDs to ignore
SAMPLING_ADMIN_USERS""Comma-separated user IDs who can use admin commands

Rate Limiting

VariableDefaultDescription
SAMPLING_RATE_LIMIT_USER10Max requests per user per minute
SAMPLING_RATE_LIMIT_CHAT20Max requests per chat per minute

Message Type Support

VariableDefaultDescription
SAMPLING_ENABLE_TEXTtrueEnable text messages
SAMPLING_ENABLE_PHOTOtrueEnable photo messages
SAMPLING_ENABLE_DOCUMENTtrueEnable document uploads
SAMPLING_ENABLE_VOICEtrueEnable voice messages
SAMPLING_ENABLE_VIDEOtrueEnable video messages
SAMPLING_ENABLE_STICKERtrueEnable sticker messages
SAMPLING_ENABLE_LOCATIONtrueEnable location sharing
SAMPLING_ENABLE_CONTACTtrueEnable contact sharing
SAMPLING_ENABLE_POLLtrueEnable poll messages

Content Filtering

VariableDefaultDescription
SAMPLING_MIN_MESSAGE_LENGTH1Minimum message length
SAMPLING_MAX_MESSAGE_LENGTH1000Maximum message length
SAMPLING_KEYWORD_TRIGGERS""Only respond to messages with these keywords
SAMPLING_IGNORE_COMMANDStrueIgnore messages starting with /

Usage Examples

Market Discovery

  • "Send a message to @mychannel saying hello"
  • "Get information about @telegram channel"
  • "Forward message 123 from @source to @destination"

Bot Commands

  • /start: Initialize the bot and get a welcome message
  • /help: Get help information about available features
  • /config: View current configuration (admin users only)

MCP Tools

FORWARD_MESSAGE

Forward a message from one chat to another

ParameterTypeRequiredDescription
fromChatIdstringnumberYes
toChatIdstringnumberYes
messageIdnumberYesID of the message to forward
disableNotificationbooleanForward message silently

GET_CHANNEL_INFO

Get information about a Telegram channel or chat

ParameterTypeRequiredDescription
channelIdstringnumberYes

GET_CHANNEL_MEMBERS

Get a list of channel administrators and members

ParameterTypeRequiredDefaultDescription
channelIdstringnumberYes
limitnumber10Maximum number of members to retrieve (1-50)

PIN_MESSAGE

Pin a message in a Telegram chat or channel

ParameterTypeRequiredDescription
chatIdstringnumberYes
messageIdnumberYesID of the message to pin
disableNotificationbooleanPin message silently

SEND_MESSAGE

Send a message to a Telegram chat or channel

ParameterTypeRequiredDescription
chatIdstringnumberYes
textstringYesThe message text to send
topicIdnumberThe topic ID for forum channels (optional)
parseModestringParse mode for Telegram rendering. Use Text for plain text without formatting.

Development

Build Project

pnpm run build

Development Mode (Watch)

pnpm run watch

Linting & Formatting

pnpm run lint
pnpm run format

Project Structure

  • src/tools/: Individual tool definitions
  • src/services/: Telegram service and bot logic
  • src/sampling/: AI sampling feature implementation
  • src/config.ts: Configuration with Zod validation
  • src/index.ts: Server entry point

Getting Your Bot Token

  1. Message @BotFather on Telegram
  2. Use /newbot command
  3. Follow the prompts to create your bot
  4. Copy the bot token provided
  5. Set it as an environment variable

Resources

Disclaimer

This project is an unofficial tool. Users should ensure their bot usage complies with Telegram's Terms of Service and Bot API policies.

License