Skip to main content
Glama

send_audio

Send an audio file (music) to a Telegram chat. Supports MP3/M4A URLs, optional caption, performer, title, and silent notification.

Instructions

Send an audio file (music) to a Telegram chat.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYesTarget chat ID.
audio_urlYesURL or file_id of the audio (MP3/M4A).
captionNoOptional caption.
parse_modeNoHTML, Markdown, MarkdownV2, or None.HTML
performerNoPerformer name.
titleNoTrack title.
disable_notificationNoSend silently.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYes
errorNo
message_idNo
chat_idNo

Implementation Reference

  • The send_audio async function that executes the tool logic: validates chat permission, applies rate limiting, calls ctx.bot.send_audio(), and returns a SendMediaResult.
    async def send_audio(
        chat_id: int,
        audio_url: str,
        caption: str | None = None,
        parse_mode: str | None = "HTML",
        performer: str | None = None,
        title: str | None = None,
        disable_notification: bool = False,
    ) -> SendMediaResult:
        """Send an audio file (music) to a Telegram chat.
    
        Args:
            chat_id: Target chat ID.
            audio_url: URL or file_id of the audio (MP3/M4A).
            caption: Optional caption.
            parse_mode: HTML, Markdown, MarkdownV2, or None.
            performer: Performer name.
            title: Track title.
            disable_notification: Send silently.
        """
        if not ctx.is_chat_allowed(chat_id):
            result = SendMediaResult(ok=False, error=f"Chat {chat_id} is not allowed.")
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "send_audio",
                    {"chat_id": chat_id, "audio_url": audio_url},
                    result.ok,
                    result.error,
                )
            return result
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            msg = await ctx.bot.send_audio(
                chat_id=chat_id,
                audio=audio_url,
                caption=caption,
                parse_mode=normalize_parse_mode(parse_mode),
                performer=performer,
                title=title,
                disable_notification=disable_notification,
            )
            result = SendMediaResult(ok=True, message_id=msg.message_id, chat_id=msg.chat.id)
        except ValueError as exc:
            result = SendMediaResult(ok=False, error=str(exc))
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = SendMediaResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "send_audio",
                {"chat_id": chat_id, "audio_url": audio_url},
                result.ok,
                result.error,
            )
        return result
  • SendMediaResult response model (extends ToolResponse) with message_id and chat_id fields.
    class SendMediaResult(ToolResponse):
        message_id: int | None = None
        chat_id: int | None = None
  • ToolResponse base model with ok/error fields.
    class ToolResponse(BaseModel):
        """Base model for all tool results. ok=True on success, ok=False with error on failure."""
    
        ok: bool
        error: str | None = None
  • register_media_tools() function registers send_audio (and other media tools) onto the FastMCP instance via @mcp.tool decorator. Called from server.py line 102.
    def register_media_tools(
        mcp: FastMCP, ctx: BotContext, allowed_tools: set[str] | None = None
    ) -> None:
        if allowed_tools is None or "send_document" in allowed_tools:
    
            @mcp.tool
            async def send_document(
                chat_id: int,
                document_url: str,
                caption: str | None = None,
                parse_mode: str | None = "HTML",
                disable_notification: bool = False,
            ) -> SendMediaResult:
                """Send a document/file to a Telegram chat.
    
                Args:
                    chat_id: Target chat ID.
                    document_url: URL or file_id of the document.
                    caption: Optional caption.
                    parse_mode: HTML, Markdown, MarkdownV2, or None.
                    disable_notification: Send silently.
                """
                if not ctx.is_chat_allowed(chat_id):
                    result = SendMediaResult(ok=False, error=f"Chat {chat_id} is not allowed.")
                    if ctx.audit_logger:
                        ctx.audit_logger.log(
                            "send_document",
                            {"chat_id": chat_id, "document_url": document_url},
                            result.ok,
                            result.error,
                        )
                    return result
    
                try:
                    if ctx.rate_limiter:
                        await ctx.rate_limiter.acquire()
                    msg = await ctx.bot.send_document(
                        chat_id=chat_id,
                        document=document_url,
                        caption=caption,
                        parse_mode=normalize_parse_mode(parse_mode),
                        disable_notification=disable_notification,
                    )
                    result = SendMediaResult(ok=True, message_id=msg.message_id, chat_id=msg.chat.id)
                except ValueError as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
                except (TelegramBadRequest, TelegramForbiddenError) as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
    
                if ctx.audit_logger:
                    ctx.audit_logger.log(
                        "send_document",
                        {"chat_id": chat_id, "document_url": document_url},
                        result.ok,
                        result.error,
                    )
                return result
    
        if allowed_tools is None or "send_voice" in allowed_tools:
    
            @mcp.tool
            async def send_voice(
                chat_id: int,
                voice_url: str,
                caption: str | None = None,
                parse_mode: str | None = "HTML",
                duration: int | None = None,
                disable_notification: bool = False,
            ) -> SendMediaResult:
                """Send a voice message to a Telegram chat.
    
                Args:
                    chat_id: Target chat ID.
                    voice_url: URL or file_id of the voice message (OGG with OPUS).
                    caption: Optional caption.
                    parse_mode: HTML, Markdown, MarkdownV2, or None.
                    duration: Duration in seconds.
                    disable_notification: Send silently.
                """
                if not ctx.is_chat_allowed(chat_id):
                    result = SendMediaResult(ok=False, error=f"Chat {chat_id} is not allowed.")
                    if ctx.audit_logger:
                        ctx.audit_logger.log(
                            "send_voice",
                            {"chat_id": chat_id, "voice_url": voice_url},
                            result.ok,
                            result.error,
                        )
                    return result
    
                try:
                    if ctx.rate_limiter:
                        await ctx.rate_limiter.acquire()
                    msg = await ctx.bot.send_voice(
                        chat_id=chat_id,
                        voice=voice_url,
                        caption=caption,
                        parse_mode=normalize_parse_mode(parse_mode),
                        duration=duration,
                        disable_notification=disable_notification,
                    )
                    result = SendMediaResult(ok=True, message_id=msg.message_id, chat_id=msg.chat.id)
                except ValueError as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
                except (TelegramBadRequest, TelegramForbiddenError) as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
    
                if ctx.audit_logger:
                    ctx.audit_logger.log(
                        "send_voice",
                        {"chat_id": chat_id, "voice_url": voice_url},
                        result.ok,
                        result.error,
                    )
                return result
    
        if allowed_tools is None or "send_video" in allowed_tools:
    
            @mcp.tool
            async def send_video(
                chat_id: int,
                video_url: str,
                caption: str | None = None,
                parse_mode: str | None = "HTML",
                duration: int | None = None,
                disable_notification: bool = False,
            ) -> SendMediaResult:
                """Send a video to a Telegram chat.
    
                Args:
                    chat_id: Target chat ID.
                    video_url: URL or file_id of the video.
                    caption: Optional caption.
                    parse_mode: HTML, Markdown, MarkdownV2, or None.
                    duration: Duration in seconds.
                    disable_notification: Send silently.
                """
                if not ctx.is_chat_allowed(chat_id):
                    result = SendMediaResult(ok=False, error=f"Chat {chat_id} is not allowed.")
                    if ctx.audit_logger:
                        ctx.audit_logger.log(
                            "send_video",
                            {"chat_id": chat_id, "video_url": video_url},
                            result.ok,
                            result.error,
                        )
                    return result
    
                try:
                    if ctx.rate_limiter:
                        await ctx.rate_limiter.acquire()
                    msg = await ctx.bot.send_video(
                        chat_id=chat_id,
                        video=video_url,
                        caption=caption,
                        parse_mode=normalize_parse_mode(parse_mode),
                        duration=duration,
                        disable_notification=disable_notification,
                    )
                    result = SendMediaResult(ok=True, message_id=msg.message_id, chat_id=msg.chat.id)
                except ValueError as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
                except (TelegramBadRequest, TelegramForbiddenError) as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
    
                if ctx.audit_logger:
                    ctx.audit_logger.log(
                        "send_video",
                        {"chat_id": chat_id, "video_url": video_url},
                        result.ok,
                        result.error,
                    )
                return result
    
        if allowed_tools is None or "send_animation" in allowed_tools:
    
            @mcp.tool
            async def send_animation(
                chat_id: int,
                animation_url: str,
                caption: str | None = None,
                parse_mode: str | None = "HTML",
                disable_notification: bool = False,
            ) -> SendMediaResult:
                """Send a GIF/animation to a Telegram chat.
    
                Args:
                    chat_id: Target chat ID.
                    animation_url: URL or file_id of the animation.
                    caption: Optional caption.
                    parse_mode: HTML, Markdown, MarkdownV2, or None.
                    disable_notification: Send silently.
                """
                if not ctx.is_chat_allowed(chat_id):
                    result = SendMediaResult(ok=False, error=f"Chat {chat_id} is not allowed.")
                    if ctx.audit_logger:
                        ctx.audit_logger.log(
                            "send_animation",
                            {"chat_id": chat_id, "animation_url": animation_url},
                            result.ok,
                            result.error,
                        )
                    return result
    
                try:
                    if ctx.rate_limiter:
                        await ctx.rate_limiter.acquire()
                    msg = await ctx.bot.send_animation(
                        chat_id=chat_id,
                        animation=animation_url,
                        caption=caption,
                        parse_mode=normalize_parse_mode(parse_mode),
                        disable_notification=disable_notification,
                    )
                    result = SendMediaResult(ok=True, message_id=msg.message_id, chat_id=msg.chat.id)
                except ValueError as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
                except (TelegramBadRequest, TelegramForbiddenError) as exc:
                    result = SendMediaResult(ok=False, error=str(exc))
    
                if ctx.audit_logger:
                    ctx.audit_logger.log(
                        "send_animation",
                        {"chat_id": chat_id, "animation_url": animation_url},
                        result.ok,
                        result.error,
                    )
                return result
    
        if allowed_tools is None or "send_audio" in allowed_tools:
  • Permission mapping: 'send_audio' is assigned PermissionLevel.MESSAGING.
    "send_audio": PermissionLevel.MESSAGING,
Behavior2/5

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

No annotations are provided, so the description must carry the full burden. It only states the basic action without disclosing side effects, authorization requirements, rate limits, or restrictions (e.g., file size limits, bot permissions).

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 single sentence, concise and front-loaded with the main action. No wasted words, though it could be slightly expanded for clarity.

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

Completeness3/5

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

With an output schema presumably documenting return values, the description is adequate but minimal. Given the rich schema and many sibling tools, more context about typical usage patterns would improve completeness.

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%, so the baseline is 3. The description adds no extra meaning beyond the schema; it just mentions 'audio file' which is already covered by the audio_url parameter description.

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 'Send an audio file (music) to a Telegram chat,' specifying the action (send), resource (audio/music), and destination (Telegram chat). This distinguishes it from sibling tools like send_document or send_voice.

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 send_voice or send_document. With many sibling tools, the description should provide context, but it does not.

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/Py2755/aiogram-mcp'

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