Skip to main content
Glama
aahl

MCP Server for notify to weixin / telegram / bark / lark

by aahl

Telegram send audio

tg_send_audio

Send audio messages to Telegram chats using a bot. Provide an audio URL or base64 data URI, with optional caption and reply settings.

Instructions

Send audio via telegram bot

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
audioYesAudio URL or base64 data URI (e.g., data:audio/wav;base64,...
chat_idNoTelegram chat id, Default to get from environment variables
captionNoAudio caption, 0-1024 characters after entities parsing
parse_modeNoMode for parsing entities in the caption. [text/MarkdownV2]
reply_to_message_idNoIdentifier of the message that will be replied to

Implementation Reference

  • The tool 'tg_send_audio' is registered via the @mcp.tool decorator with title 'Telegram send audio' and description 'Send audio via telegram bot'. The decorator is how FastMCP registers tools.
    @mcp.tool(
        title="Telegram send audio",
        description="Send audio via telegram bot",
    )
    async def tg_send_audio(
        audio: str = Field(description="Audio URL or base64 data URI (e.g., data:audio/wav;base64,..."),
        chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"),
        caption: str = Field("", description="Audio caption, 0-1024 characters after entities parsing"),
        parse_mode: str = Field("", description=f"Mode for parsing entities in the caption. [text/MarkdownV2]"),
        reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"),
    ):
        if parse_mode == TELEGRAM_MARKDOWN_V2:
            caption = telegramify_markdown.markdownify(caption)
    
        if audio.startswith("data:"):
            match = re.match(r"data:audio/([^;]+);base64,(.*)", audio)
            if not match:
                return {"error": "Invalid base64 data URL format"}
            try:
                datas = base64.b64decode(match.group(2))
                audio = InputFile(io.BytesIO(datas), f"audio.{match.group(1)}")
            except Exception as e:
                return {"error": f"Failed to decode base64: {str(e)}"}
    
        res = await bot.send_audio(
            chat_id=chat_id or TELEGRAM_DEFAULT_CHAT,
            audio=audio,
            caption=caption or None,
            parse_mode=parse_mode if parse_mode in [TELEGRAM_MARKDOWN_V2] else None,
            reply_to_message_id=reply_to_message_id or None,
        )
        return res.to_json()
  • The tg_send_audio async function is the handler. It accepts audio (URL or base64 data URI), chat_id, caption, parse_mode, and reply_to_message_id. It decodes base64 data URIs for audio files and calls bot.send_audio() to send the audio via Telegram.
    async def tg_send_audio(
        audio: str = Field(description="Audio URL or base64 data URI (e.g., data:audio/wav;base64,..."),
        chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"),
        caption: str = Field("", description="Audio caption, 0-1024 characters after entities parsing"),
        parse_mode: str = Field("", description=f"Mode for parsing entities in the caption. [text/MarkdownV2]"),
        reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"),
    ):
        if parse_mode == TELEGRAM_MARKDOWN_V2:
            caption = telegramify_markdown.markdownify(caption)
    
        if audio.startswith("data:"):
            match = re.match(r"data:audio/([^;]+);base64,(.*)", audio)
            if not match:
                return {"error": "Invalid base64 data URL format"}
            try:
                datas = base64.b64decode(match.group(2))
                audio = InputFile(io.BytesIO(datas), f"audio.{match.group(1)}")
            except Exception as e:
                return {"error": f"Failed to decode base64: {str(e)}"}
    
        res = await bot.send_audio(
            chat_id=chat_id or TELEGRAM_DEFAULT_CHAT,
            audio=audio,
            caption=caption or None,
            parse_mode=parse_mode if parse_mode in [TELEGRAM_MARKDOWN_V2] else None,
            reply_to_message_id=reply_to_message_id or None,
        )
        return res.to_json()
  • The input parameters are defined via Pydantic Field descriptors: audio (str), chat_id (str), caption (str), parse_mode (str), reply_to_message_id (int). These serve as the input schema for the tool.
    async def tg_send_audio(
        audio: str = Field(description="Audio URL or base64 data URI (e.g., data:audio/wav;base64,..."),
        chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"),
        caption: str = Field("", description="Audio caption, 0-1024 characters after entities parsing"),
        parse_mode: str = Field("", description=f"Mode for parsing entities in the caption. [text/MarkdownV2]"),
        reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"),
    ):
  • The add_tools function creates the Bot instance with TELEGRAM_BOT_TOKEN and configures the base URLs. This is the setup/registration entry point called from __init__.py (line 20: tgbot.add_tools(mcp)).
    def add_tools(mcp: FastMCP, logger=None):
        bot = Bot(
            TELEGRAM_BOT_TOKEN,
            base_url=f"{TELEGRAM_BASE_URL}/bot",
            base_file_url=f"{TELEGRAM_BASE_URL}/file/bot",
        ) if TELEGRAM_BOT_TOKEN else None
  • The registration call chain: __init__.py calls tgbot.add_tools(mcp) which registers all Telegram tools including tg_send_audio.
    tgbot.add_tools(mcp)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.1.11
    • changedInput schema / properties / audio / description
      Previous value: -"Audio URL"New value: +"Audio URL or base64 data URI (e.g., data:audio/wav;base64,..."
  2. Changed1 schema field changedv1.0.0
    • addedInput schema / properties / reply_to_message_id
      Added value: +{
      +  "default": 0,
      +  "description": "Identifier of the message that will be replied to",
      +  "type": "integer"
      +}
  3. First observed

TDQS

C2.3/5.0
Behavior1/5

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

No annotations are provided, and the description adds no behavioral details (e.g., file size limits, format requirements, authentication). The tool's behavior is opaque beyond what the name implies.

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

Conciseness3/5

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

The description is a single sentence, which is concise, but it lacks structure and fails to elaborate on key aspects. It is minimally adequate.

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

Completeness2/5

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

With 5 parameters, no output schema, and no annotations, the description is incomplete. It does not explain how to provide the audio or the default behavior for chat_id.

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 coverage is 100%, so parameters are documented. The description adds no additional meaning beyond the schema, leaving baseline at 3.

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

Purpose3/5

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

Description states 'Send audio via telegram bot', which is a verb+resource, but it does not differentiate from siblings like tg_send_file which could also send audio files. The purpose is clear but could be more specific.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives like tg_send_file or tg_send_voice. The description provides no context for selection.

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