Skip to main content
Glama
archetyx
by archetyx

telegram_send_image

Send images from your AI coding assistant to Telegram for sharing charts, visualizations, screenshots, and diagrams. Supports PNG, JPG, GIF, and WebP formats with optional captions.

Instructions

        发送图片到 Telegram

        ⚠️ 使用场景:
        - 生成了图表、可视化结果
        - 创建了截图、示意图
        - 需要用户查看图片内容
        - 图片格式:PNG, JPG, GIF, WebP 等

        参数:
        - image_path: 图片文件路径(相对于项目目录或绝对路径)
        - caption: 可选说明文字

        示例:
        telegram_send_image(
            image_path="output/chart.png",
            caption="性能测试结果图表"
        )
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
captionNo可选说明文字
image_pathYes图片文件路径

Implementation Reference

  • The handler function that executes the telegram_send_image tool: validates input, resolves image path relative to project, checks file existence, constructs caption, and sends the image to Telegram using the sendPhoto API endpoint.
    async def handle_telegram_send_image(session, arguments: dict) -> list[TextContent]:
        """Handle telegram_send_image tool"""
        image_path = arguments.get("image_path", "")
        caption = arguments.get("caption", "")
    
        if not image_path:
            return [TextContent(type="text", text="错误: image_path 参数不能为空")]
    
        # Resolve image path (relative to project or absolute)
        if not os.path.isabs(image_path):
            full_path = os.path.join(session.project_path, image_path)
        else:
            full_path = image_path
    
        # Check if file exists
        if not os.path.exists(full_path):
            return [TextContent(
                type="text",
                text=f"❌ 图片文件不存在: {image_path}"
            )]
    
        if not os.path.isfile(full_path):
            return [TextContent(
                type="text",
                text=f"❌ 不是文件(可能是目录): {image_path}"
            )]
    
        # Build caption
        if not caption:
            caption = f"🖼️ [{session.session_id}] {image_path}"
        else:
            caption = f"🖼️ [{session.session_id}] {caption}"
    
        # Update session
        session.update_activity()
    
        # Send image to Telegram using HTTP API
        try:
            import httpx
    
            url = f"https://api.telegram.org/bot{config.TELEGRAM_BOT_TOKEN}/sendPhoto"
    
            with open(full_path, 'rb') as f:
                files = {'photo': (os.path.basename(image_path), f, 'image/jpeg')}
                data = {
                    'chat_id': session.chat_id,
                    'caption': caption
                }
    
                async with httpx.AsyncClient() as client:
                    response = await client.post(url, files=files, data=data, timeout=30.0)
                    response.raise_for_status()
    
            return [TextContent(
                type="text",
                text=f"✅ 已发送图片到 Telegram (会话: {session.session_id}, 图片: {image_path})"
            )]
        except Exception as e:
            return [TextContent(
                type="text",
                text=f"❌ 发送图片失败: {str(e)}"
            )]
  • Registration of the telegram_send_image tool in the list_tools() decorator, including name, description, and input schema definition.
    Tool(
        name="telegram_send_image",
        description="""
        发送图片到 Telegram
    
        ⚠️ 使用场景:
        - 生成了图表、可视化结果
        - 创建了截图、示意图
        - 需要用户查看图片内容
        - 图片格式:PNG, JPG, GIF, WebP 等
    
        参数:
        - image_path: 图片文件路径(相对于项目目录或绝对路径)
        - caption: 可选说明文字
    
        示例:
        telegram_send_image(
            image_path="output/chart.png",
            caption="性能测试结果图表"
        )
        """,
        inputSchema={
            "type": "object",
            "properties": {
                "image_path": {
                    "type": "string",
                    "description": "图片文件路径"
                },
                "caption": {
                    "type": "string",
                    "description": "可选说明文字"
                }
            },
            "required": ["image_path"]
        }
    ),
  • Dispatch logic in the main @server.call_tool() function that routes calls to the telegram_send_image handler.
    elif name == "telegram_send_image":
        return await handle_telegram_send_image(session, arguments)
  • Input schema definition for the telegram_send_image tool, specifying required image_path and optional caption.
    inputSchema={
        "type": "object",
        "properties": {
            "image_path": {
                "type": "string",
                "description": "图片文件路径"
            },
            "caption": {
                "type": "string",
                "description": "可选说明文字"
            }
        },
        "required": ["image_path"]
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It mentions the tool sends images to Telegram but doesn't disclose behavioral traits like authentication requirements, rate limits, error handling, or what happens if the image path is invalid. The warning symbol (⚠️) introduces usage scenarios rather than behavioral risks. Some context is provided about file path handling ('相对于项目目录或绝对路径'), but key behavioral aspects remain undocumented.

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 well-structured with clear sections (purpose, usage scenarios, parameters, example) and uses bullet points effectively. It's appropriately sized for a 2-parameter tool. Minor improvements could include tighter phrasing (e.g., the usage scenarios could be more concise), but overall it's efficient with zero wasted sentences.

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?

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is reasonably complete. It covers purpose, usage guidelines, parameters, and provides an example. The main gap is the lack of behavioral transparency (no info on authentication, errors, etc.), but for a sending tool with good parameter coverage and clear usage context, it's mostly adequate.

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

Parameters3/5

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

Schema description coverage is 100%, with both parameters clearly documented in the schema. The description adds minimal value beyond the schema: it restates that 'image_path' is a file path and 'caption' is optional text, and provides an example showing usage. However, it doesn't add significant semantic context like path format details or caption length limits beyond what the schema already provides.

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 purpose as '发送图片到 Telegram' (send image to Telegram), which is a specific verb+resource combination. It distinguishes itself from siblings like telegram_send (general sending), telegram_send_file (file sending), and telegram_send_code (code sending) by focusing specifically on images. The Chinese title reinforces this specificity.

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

Usage Guidelines5/5

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

The description provides explicit usage scenarios in a dedicated '使用场景' section, listing four specific cases when to use this tool (e.g., '生成了图表、可视化结果', '创建了截图、示意图'). It also specifies supported image formats (PNG, JPG, GIF, WebP), giving clear context for when this tool is appropriate versus alternatives like telegram_send_file for non-image files.

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

Install Server

Other Tools

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/archetyx/telegram-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server