Skip to main content
Glama
telegram-mcp

telegram-mcp

by EyalWerber

telegram-mcp

将某个 Telegram 群组中的最新图片交给 Claude。

这些截图由机器人发布,而 Telegram Bot API 永远不会返回机器人自己的消息——所以这里通过 MTProto(Telethon)使用 用户 账户读取群组。这是看到这些照片的唯一方式。

一次性设置

  1. 从 https://my.telegram.org → API 开发工具获取 API ID 和哈希值。

  2. 执行 cp .env.example .env 并填写 TELEGRAM_API_ID、TELEGRAM_API_HASH 和 TELEGRAM_CHAT_ID(群组的数字 ID,取负数)。

  3. 创建环境:

    python -m venv .venv
    .venv\Scripts\pip install -e .[dev]
  4. 在终端中登录,而不是通过 Claude:

    .venv\Scripts\telegram-mcp-login

    它会要求你输入手机号码、Telegram 发送的验证码,以及(如果有)两步验证密码,然后写入 session/telegram.session。

    它还会列出你的对话框一次,并把群组名称回显给你。列表功能让会话此后能够解析出超级群组——Telegram 会在机器人加入群组后立即把它升级为超级群组——而这个名称正是你确认 TELEGRAM_CHAT_ID 指向预期位置的依据。如果找不到该群组,它会明确说明并以非零状态退出。

Related MCP server: image-relay-mcp

安装到 Claude

claude mcp add --scope user telegram -- <abs path>\.venv\Scripts\python -m telegram_mcp.server

用户级作用域,因此每个项目都能使用。

工具

  • get_latest_image() — 返回群组中的最新图片,最多回看 200 条消息。

  • wait_for_next_image(timeout_seconds=120) — 阻塞,直到有比调用时刻更新的图片到达。等待不消耗令牌;进程在 socket 上空闲等待。限制在 1–240 秒,以确保不超出 MCP 客户端的工具超时。

两者都返回图片(JPEG,长边 ≤1568 像素)和一行文本:先是原始图片的路径,然后依次是消息 ID、时间戳、发送者和带引号的说明文字。当缩放后的小字细节丢失时,请裁剪原始图片。

同一时间只能有一个进程持有该会话。当第一个 Claude Code 会话正在调用时,第二个会话若调用工具会被告知稍后重试,而不是收到 SQLite 错误。

测试

.venv\Scripts\python -m pytest

无需网络,也无需 Telegram 账户——Telethon 全程被模拟。

安全

session/telegram.session 是你 Telegram 账户的完整登录凭据。它已被 gitignore,且永远不会离开这台机器。任何持有该文件的人都能读取你的消息;如果你怀疑它已被复制,请删除它并重新登录。凭据只存在于 .env 中——绝不要出现在文档、提示词或工单中。

Available Tools

2 tools
get_latest_imageA

Return the most recent image posted in the configured Telegram group.

Use this when the user says they have just sent a screenshot. It looks back over the last 200 messages for one carrying a photo and returns it together with the path to the full-resolution original — crop that file if you need to read fine print the downscaled copy blurred.

Returns a sentence explaining what to fix if the group is unreachable, the session has expired, or no photo is in range.

NameRequiredDescriptionDefault

No parameters

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses that it scans the last 200 messages, returns a downscaled photo along with the path to the full-resolution original, and provides an error sentence for unreachable group, expired session, or no photo. This gives agents a clear picture of behavior beyond the schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a bit long but each paragraph serves a purpose: primary action, usage guidance, and error handling. It is front-loaded with the main action and each sentence adds value, though it could be slightly more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter tool with no output schema and no annotations, the description covers the what, when, return value, and failure modes. It doesn't specify the exact success return format, but it mentions the image and path to the original, which is sufficient for an agent to use correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are zero parameters, so the schema already covers everything. The description mentions a 'configured Telegram group' implying external context, but no parameter explanation is needed. The baseline for no parameters is 4, and the description doesn't introduce any confusion.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's action: 'Return the most recent image posted in the configured Telegram group.' It uses a specific verb and resource, and implicitly distinguishes from the sibling wait_for_next_image by focusing on 'most recent' rather than awaiting new ones.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit when-to-use guidance: 'Use this when the user says they have just sent a screenshot.' It also explains the lookback window (last 200 messages) and advises cropping for fine print. It doesn't explicitly name the alternative tool, but the context implies when not to use it (waiting for a new image).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

wait_for_next_imageA

Blocks until a new image is posted to the group, then returns it.

Use this when the user is about to send a screenshot. It notes the group's newest message when the call starts and returns the first photo after that, so it never hands back something you have already seen in this call.

Args: timeout_seconds: how long to wait, clamped to 1-240 seconds.

Waiting costs no tokens -- the process idles on a socket. If nothing arrives it returns a sentence saying so; call it again to keep waiting.

NameRequiredDescriptionDefault
timeout_secondsNo

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It does so thoroughly: it blocks, notes the newest message at call start, returns only the first photo after that, guarantees no duplicate images from prior calls, costs no tokens (idles on a socket), clamps the timeout to 1-240 seconds, and describes the no-result behavior ('returns a sentence saying so'). These are non-obvious, valuable behavioral details that an agent needs to use the tool correctly.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is succinct yet complete, using a clear structure: purpose, usage, and behavior. It front-loads the primary function, then adds usage context, then details the parameter and behavioral notes. Every sentence adds value; there is no fluff or redundancy. It is appropriately sized for a tool with a single parameter and no output schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple (one optional param, no output schema), and the description covers all essential aspects: what it does, when to use it, how the timeout works, the blocking/token behavior, and what it returns (both success and no-result cases). No critical information is missing for an agent to call it correctly. The absence of an output schema is mitigated by the explicit description of the return value.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has only one parameter, timeout_seconds, and the schema provides no description (coverage 0%). The description compensates fully by explaining 'how long to wait' and adding the constraint 'clamped to 1-240 seconds.' This goes beyond the raw schema (which only shows a default of 120) and gives the agent complete understanding of the parameter's meaning and bounds.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Blocks until a new image is posted to the group, then returns it.' It immediately clarifies the distinct semantics (waits for a new image rather than returning the latest), and explicitly states it 'never hands back something you have already seen in this call,' which distinguishes it from the sibling get_latest_image. The purpose is unambiguous and precisely scoped.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides a concrete usage context: 'Use this when the user is about to send a screenshot.' It also explains that it can be called again to keep waiting. However, it does not explicitly mention the sibling tool or state when not to use this tool versus get_latest_image. The guidance is clear for the primary scenario but lacks explicit exclusion or alternative routing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv0.1.0
    • First observedget_latest_image
    • First observedwait_for_next_image

TDQS

A4.4/5.0

Scored across 2 tools

Disambiguation5/5

The two tools are clearly distinct: get_latest_image retrieves a previously posted photo, while wait_for_next_image blocks for a new one. The use cases do not overlap in an ambiguous way.

Naming Consistency4/5

Both names follow a verb-noun structure and clearly communicate function. The slight mix of 'get_' and 'wait_for_' is a minor deviation but still predictable.

Tool Count3/5

Two tools is at the low end of a reasonable scope for a narrow image-receiving server. They cover the core need without bloat, but the server feels rather thin.

Completeness4/5

The pair covers the two key workflows: retrieving a previous screenshot and waiting for a new one. Missing features like explicit image search or sending could be useful, but they are not essential for the server's obvious intent.

Maintenance

ActivityStale
ResponsivenessNo recent community issues

Related MCP Connectors

Related MCP Servers