Skip to main content
Glama

edit_message

Edit the text and inline keyboard of a sent message in a Telegram chat.

Instructions

Edit the text and/or inline keyboard of an existing message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYesChat containing the message.
message_idYesID of the message to edit.
textYesNew message text.
buttonsNoNew inline keyboard (None to remove buttons).
parse_modeNoHTML, Markdown, MarkdownV2, or None.HTML

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYes
errorNo
message_idNo
chat_idNo

Implementation Reference

  • The MCP tool handler for 'edit_message'. Edits the text and/or inline keyboard of an existing Telegram message using ctx.bot.edit_message_text(). Supports chat permission checks, button validation via _build_keyboard(), rate limiting, parse mode normalization, and audit logging.
    @mcp.tool
    async def edit_message(
        chat_id: int,
        message_id: int,
        text: str,
        buttons: list[list[dict[str, str]]] | None = None,
        parse_mode: str | None = "HTML",
    ) -> EditMessageResult:
        """Edit the text and/or inline keyboard of an existing message.
    
        Args:
            chat_id: Chat containing the message.
            message_id: ID of the message to edit.
            text: New message text.
            buttons: New inline keyboard (None to remove buttons).
            parse_mode: HTML, Markdown, MarkdownV2, or None.
        """
        if not ctx.is_chat_allowed(chat_id):
            result = EditMessageResult(
                ok=False,
                error=f"Chat {chat_id} is not in allowed_chat_ids.",
            )
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "edit_message",
                    {"chat_id": chat_id, "message_id": message_id, "text": text},
                    result.ok,
                    result.error,
                )
            return result
    
        reply_markup = None
        if buttons is not None:
            keyboard = _build_keyboard(buttons)
            if isinstance(keyboard, str):
                result = EditMessageResult(ok=False, error=keyboard)
                if ctx.audit_logger:
                    ctx.audit_logger.log(
                        "edit_message",
                        {"chat_id": chat_id, "message_id": message_id, "text": text},
                        result.ok,
                        result.error,
                    )
                return result
            reply_markup = keyboard
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            api_result = await ctx.bot.edit_message_text(
                chat_id=chat_id,
                message_id=message_id,
                text=text,
                parse_mode=normalize_parse_mode(parse_mode),
                reply_markup=reply_markup,
            )
            if isinstance(api_result, bool):
                result = EditMessageResult(ok=True, message_id=message_id, chat_id=chat_id)
            else:
                result = EditMessageResult(
                    ok=True,
                    message_id=api_result.message_id,
                    chat_id=api_result.chat.id,
                )
        except ValueError as exc:
            result = EditMessageResult(ok=False, error=str(exc))
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = EditMessageResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "edit_message",
                {"chat_id": chat_id, "message_id": message_id, "text": text},
                result.ok,
                result.error,
            )
        return result
  • Pydantic response model for the edit_message tool, extending ToolResponse with optional message_id and chat_id fields.
    class EditMessageResult(ToolResponse):
        message_id: int | None = None
        chat_id: int | None = None
  • Conditional registration of the edit_message tool via the @mcp.tool decorator within register_interactive_tools(), gated by the allowed_tools set.
    if allowed_tools is None or "edit_message" in allowed_tools:
  • Registration call site in AiogramMCP._register_tools() that triggers the interactive tools registration (including edit_message).
    register_interactive_tools(self._mcp, self._ctx, allowed_tools=at)
  • Permission mapping declaring edit_message at the MESSAGING permission level.
    "edit_message": 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 disclose behavioral traits. It fails to mention permissions, limitations (e.g., can only edit own bot's messages), or side effects. The description only states the basic action without caveats.

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?

Single sentence, concise, and front-loaded with the action. No superfluous words.

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?

Given the low complexity, existence of output schema, and full schema coverage, the description is minimally adequate. However, missing behavioral context reduces 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 schema already documents all parameters. The description adds minimal value beyond stating 'text and/or inline keyboard', which is redundant with the schema. Baseline 3 is appropriate.

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 'Edit the text and/or inline keyboard of an existing message' clearly specifies the action (edit) and the resource (message) and distinguishes from siblings like send_message (create) and delete_message (remove).

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

Usage Guidelines3/5

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

No explicit guidance on when to use this tool versus alternatives. The purpose is self-evident for editing versus creating or deleting, but no exclusions or context are provided.

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