MCP Telegram

MCP Telegram

Telegram MTProto-based MCP server with 19 tools for reading, searching, sending, forwarding, and summarizing messages

Category
访问服务器

README

<div align="center">

mcp-telegram

MCP server for Telegram — let AI assistants interact with your Telegram account

MCP Server Go Version License: MIT Go Report Card mcp-telegram MCP server

mcp-telegram MCP server

</div>


Features

  • Chat Management: List, search, mute/unmute chats
  • Messages: Read, search, inspect context, send, draft, schedule, link-resolve, and backup messages
  • AI Summarization: Summarize chat conversations using multiple LLM providers
  • Secure: Session stored in macOS Keychain (file-based storage on Linux/Windows)

Installation

go install github.com/tolmachov/mcp-telegram@latest

Or build from source:

git clone https://github.com/tolmachov/mcp-telegram.git
cd mcp-telegram
make

Setup

1. Get Telegram API Credentials

  1. Go to my.telegram.org/apps
  2. Create an application
  3. Copy api_id and api_hash

2. Configure Environment

Store credentials (macOS Keychain; plaintext JSON at ~/.local/state/mcp-telegram/config.json with 0600 perms on Linux/Windows):

mcp-telegram config set TELEGRAM_API_ID 123456789
mcp-telegram config set TELEGRAM_API_HASH abcd1234efgh5678

Or use a .env file:

cp .env.example .env
# Edit .env with your credentials

3. Login to Telegram

mcp-telegram login --phone +1234567890

You'll be prompted for a verification code sent to your Telegram.

4. Configure MCP Client

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "telegram": {
      "command": "mcp-telegram",
      "args": ["run"],
      "env": {
        "TELEGRAM_API_ID": "your_api_id",
        "TELEGRAM_API_HASH": "your_api_hash"
      }
    }
  }
}

Claude Code

claude mcp add telegram -- /path/to/mcp-telegram run

Set environment variables in your .env file or pass them via --env.

Available Tools

19 tools exposed to MCP clients. Messages are identified by opaque string handles ("42" for regular, "s:42" for scheduled) — copy them back verbatim from tool outputs to follow-up calls, never parse or construct them manually.

Tool Description
GetMe Get current user information
GetChats List all chats, groups, and channels
SearchChats Fuzzy search for chats by name
GetChatInfo Get detailed information about a chat
GetMessages Get messages from a chat (set include_scheduled=true to also list pending scheduled messages in a separate field)
SearchMessages Search within one chat by substring, with optional date / sender / media / thread filters
SearchMessagesGlobal Search by substring across all chats with opaque cursor-based pagination
GetMessageContext Get messages around a specific anchor message in chronological order
SendMessage Send, reply, schedule, or draft a message. mode = send (default) / schedule / draft; reply_to_message_id works with any mode; schedule_at is RFC3339
EditMessage Edit a message; for scheduled handles, schedule_at reschedules delivery in the same call
DeleteMessage Delete a message; "s:<id>" handles cancel pending scheduled messages
ForwardMessage Forward a delivered message (scheduled handles are rejected)
ResolveMessageLink Parse t.me / tg:// message links into chat_id, message_id, and topic_message_id for forum links
MarkAsRead Mark one or more chats as read
BackupMessages Export messages to a text file (idempotent; overwrites target)
ResolveUsername Resolve @username to user/chat info
SetChatMute Mute or unmute chat notifications (muted bool + optional duration_seconds)
SummarizeChat AI-powered chat summarization via sampling / Gemini / Ollama / Anthropic
GetMedia Download photo media from a message resource URI; returns MCP image content

Available Resources

URI Description
telegram://me Current user info
telegram://chats All chats list
telegram://chat/{id}/info Detailed info for any chat ID via resource template
telegram://chats/{id} Last 100 messages from a pinned chat (dynamic resource, only for currently pinned chats)

Pinned chat resources are created dynamically for each pinned chat and refreshed in the background; clients will receive resources/list_changed when the set changes.

Available Prompts

3 parameterized prompts that MCP clients expose as slash-commands or quick actions.

Prompt Arguments Description
daily-digest periodday (default) / week / month Walks active chats and produces a per-chat digest of key updates and action items. Read-only.
chat-catchup chat (required) — ID / @username / title; periodday / week (default) / month Summarizes a specific chat and lists messages that look like they need a reply. Read-only.
find-and-reply chat (required), query (required) — what to search for, reply (required) — reply text or instruction Searches for a message, shows a draft reply, and sends only after explicit user confirmation.

Prompt Examples

Here are some example prompts you can use with AI assistants:

Message Management

  • "Check for any unread important messages in my Telegram"
  • "Summarize all my unread Telegram messages"
  • "Read and analyze my unread messages, prepare draft responses where needed"
  • "Check non-critical unread messages and give me a brief overview"
  • "Find messages mentioning 'invoice' in my work chat from last week"
  • "Open the context around this Telegram link: https://t.me/example/123"

Organization

  • "Analyze my Telegram dialogs and suggest a folder structure"
  • "Help me categorize my Telegram chats by importance"
  • "Find all work-related conversations and suggest how to organize them"

Communication

  • "Monitor specific chat for updates about [topic]"
  • "Draft a polite response to the last message in [chat]"
  • "Check if there are any unanswered questions in my chats"
  • "Resolve this Telegram message link and show me the thread context"

Backup & Export

  • "Backup my conversation with [contact] to a file"
  • "Export the last week of messages from [group]"
  • "Backup media-only updates too so nothing is silently skipped"

Chat Summarization

The SummarizeChat tool supports multiple LLM providers:

  • sampling (experimental): Uses the MCP client's LLM via MCP Sampling. Only works with clients that support sampling: VS Code, fast-agent, Continue. Does NOT work with Claude Desktop or Claude Code.
  • ollama: Local LLM via Ollama - no API key required
  • gemini: Google Gemini API
  • anthropic: Anthropic Claude API

Configure via environment variables:

SUMMARIZE_PROVIDER=ollama  # or: sampling, gemini, anthropic
SUMMARIZE_MODEL=           # provider-specific model name

Commands

# Run MCP server (used by MCP clients)
mcp-telegram run

# Login to Telegram
mcp-telegram login --phone +1234567890

# Logout and delete session
mcp-telegram logout

# Securely store config values (macOS Keychain / file on Linux)
mcp-telegram config set TELEGRAM_API_ID 123456789
mcp-telegram config set TELEGRAM_API_HASH abcd1234

# List stored keys
mcp-telegram config list

# Delete a stored value
mcp-telegram config delete TELEGRAM_API_ID

Allowed keys: TELEGRAM_API_ID, TELEGRAM_API_HASH, ANTHROPIC_API_KEY, GEMINI_API_KEY.

Configuration Options

Environment Variable Description Default
TELEGRAM_API_ID Telegram API ID Required
TELEGRAM_API_HASH Telegram API Hash Required
TELEGRAM_ALLOWED_PATHS Allowed directories for backups OS app data dir
SUMMARIZE_PROVIDER LLM provider for summarization sampling (experimental)
SUMMARIZE_MODEL Model name Provider default
SUMMARIZE_BATCH_TOKENS Tokens per summarization batch 8000
OLLAMA_URL Ollama API URL http://localhost:11434
GEMINI_API_KEY Google Gemini API key -
ANTHROPIC_API_KEY Anthropic API key -
TELEGRAM_MEDIA_MAX_BYTES Max bytes GetMedia will download per call (cap to avoid OOM on large attachments) 52428800 (50 MiB)
TELEGRAM_RATE_LIMIT_RPS RPS ceiling for history-fetching calls to Telegram. Exceeding Telegram's FLOOD_WAIT thresholds pauses all tools. 0 (safe built-in default)
TELEGRAM_PINNED_REFRESH_SECONDS Polling interval (seconds) for the pinned-chat resource watcher. 0 disables the watcher. 30

Destructive Actions

Tools like DeleteMessage request user confirmation via MCP elicitation before proceeding. If your MCP client does not support elicitation, the server relies on the LLM's instructions to confirm verbally before executing destructive operations.

Session Storage

  • macOS: Stored securely in Keychain.
  • Linux/Windows: Stored in ~/.local/state/mcp-telegram/session.json with 0600 file permissions. The file is plaintext — keep the containing user account trusted, and prefer running on macOS when handling sensitive accounts.

Config values set via mcp-telegram config set (API keys, Telegram credentials) follow the same backend: Keychain on macOS, plaintext JSON on Linux/Windows.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选