Skip to main content
Glama
archetyx
by archetyx

telegram_send_code

Send code snippets with syntax highlighting to Telegram for error debugging, bug fixes, code reviews, or when users request specific code examples.

Instructions

        发送代码段到 Telegram(带语法高亮)

        ⚠️ 使用场景(仅在必要时使用):
        - 遇到关键错误需要展示问题代码
        - 修复了重要 bug,需要展示修复方案
        - 用户明确要求查看某段代码
        - 需要用户 review 关键代码片段

        ❌ 不要使用的场景:
        - 一般性任务完成(使用 telegram_notify)
        - 创建了新文件(使用 telegram_send_file)
        - 例行操作(使用 telegram_notify 总结即可)

        参数:
        - code: 代码内容(建议不超过50行)
        - language: 编程语言(python/javascript/go/rust/bash/json/yaml等)
        - caption: 可选说明文字(建议填写,解释发送这段代码的原因)

        示例:
        telegram_send_code(
            code="def hello():\n    print('Hello')",
            language="python",
            caption="修复了空指针异常的关键函数"
        )
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
captionNo可选说明文字
codeYes代码内容
languageNo编程语言(python/javascript/go/rust/bash/json/yaml等)

Implementation Reference

  • The main handler function for the 'telegram_send_code' tool. Extracts code, language, and caption from arguments, formats a Markdown code block message, updates session activity, and sends it to Telegram via send_telegram_message. Returns success or error message.
    async def handle_telegram_send_code(session, arguments: dict) -> list[TextContent]:
        """Handle telegram_send_code tool"""
        code = arguments.get("code", "")
        language = arguments.get("language", "")
        caption = arguments.get("caption", "")
    
        if not code:
            return [TextContent(type="text", text="错误: code 参数不能为空")]
    
        # Build message
        if caption:
            message = f"📝 [`{session.session_id}`] {caption}\n\n"
        else:
            message = f"💻 [`{session.session_id}`] 代码段\n\n"
    
        # Add code block with syntax highlighting
        message += f"```{language}\n{code}\n```"
    
        # Update session
        session.update_activity()
    
        # Send to Telegram
        try:
            await send_telegram_message(session.chat_id, message)
            return [TextContent(
                type="text",
                text=f"✅ 已发送代码段到 Telegram (会话: {session.session_id}, 语言: {language or '未指定'})"
            )]
        except Exception as e:
            return [TextContent(
                type="text",
                text=f"❌ 发送代码段失败: {str(e)}"
            )]
  • Tool schema definition including name, description, and inputSchema for validation of parameters: code (required string), language (optional string), caption (optional string).
    Tool(
        name="telegram_send_code",
        description="""
        发送代码段到 Telegram(带语法高亮)
    
        ⚠️ 使用场景(仅在必要时使用):
        - 遇到关键错误需要展示问题代码
        - 修复了重要 bug,需要展示修复方案
        - 用户明确要求查看某段代码
        - 需要用户 review 关键代码片段
    
        ❌ 不要使用的场景:
        - 一般性任务完成(使用 telegram_notify)
        - 创建了新文件(使用 telegram_send_file)
        - 例行操作(使用 telegram_notify 总结即可)
    
        参数:
        - code: 代码内容(建议不超过50行)
        - language: 编程语言(python/javascript/go/rust/bash/json/yaml等)
        - caption: 可选说明文字(建议填写,解释发送这段代码的原因)
    
        示例:
        telegram_send_code(
            code="def hello():\\n    print('Hello')",
            language="python",
            caption="修复了空指针异常的关键函数"
        )
        """,
        inputSchema={
            "type": "object",
            "properties": {
                "code": {
                    "type": "string",
                    "description": "代码内容"
                },
                "language": {
                    "type": "string",
                    "description": "编程语言(python/javascript/go/rust/bash/json/yaml等)",
                    "default": ""
                },
                "caption": {
                    "type": "string",
                    "description": "可选说明文字"
                }
            },
            "required": ["code"]
        }
    ),
  • Dispatch registration in the main call_tool handler that routes calls to 'telegram_send_code' to the handle_telegram_send_code function.
    elif name == "telegram_send_code":
        return await handle_telegram_send_code(session, arguments)
Behavior4/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 adds valuable behavioral context: the tool sends code with syntax highlighting, includes a recommendation to keep code under 50 lines, and suggests adding a caption. However, it doesn't mention potential limitations like rate limits, authentication needs, or error handling, which would be helpful for a mutation tool (sending implies a write operation).

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 well-structured with clear sections (purpose, usage scenarios, parameters, example), uses bullet points for readability, and every sentence adds value. It's appropriately sized—not overly verbose—and front-loaded with the core purpose, making it efficient for an agent to parse.

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 no annotations and no output schema, the description does a good job covering the tool's purpose, usage, and parameters. It includes an example invocation, which aids understanding. However, as a mutation tool (sending code), it could benefit from more details on behavioral aspects like error responses or confirmation of success, though the example partially compensates.

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?

Schema description coverage is 100%, so the baseline is 3. The description adds meaningful semantics: it explains that 'code' should be kept under 50 lines, 'language' includes examples like python/javascript, and 'caption' is optional but recommended to explain why the code is sent. This provides practical guidance beyond the schema's basic descriptions.

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: '发送代码段到 Telegram(带语法高亮)' which translates to 'Send code snippets to Telegram (with syntax highlighting)'. It specifies the verb (send), resource (code snippets), and key feature (syntax highlighting), distinguishing it from siblings like telegram_send_file or telegram_notify.

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 guidelines with '⚠️ 使用场景(仅在必要时使用)' (scenarios to use) and '❌ 不要使用的场景' (scenarios not to use), including clear alternatives like telegram_notify and telegram_send_file. It specifies when to use (e.g., for key errors, bug fixes) and when not to use (e.g., for general task completion), helping the agent choose correctly among siblings.

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