Skip to main content
Glama

pin_message

Pin a message in a Telegram chat to keep important information visible. Optionally disable notification to avoid disturbance.

Instructions

Pin a message in a chat.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYes
message_idYes
disable_notificationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYes
errorNo

Implementation Reference

  • The pin_message tool handler function. Registers an MCP tool that pins a message in a chat via ctx.bot.pin_chat_message(). Checks chat permissions, applies rate limiting, and logs to audit.
    async def pin_message(
        chat_id: int,
        message_id: int,
        disable_notification: bool = False,
    ) -> OkResult:
        """Pin a message in a chat."""
        if not ctx.is_chat_allowed(chat_id):
            result = OkResult(ok=False, error=f"Chat {chat_id} is not allowed.")
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "pin_message",
                    {"chat_id": chat_id, "message_id": message_id},
                    result.ok,
                    result.error,
                )
            return result
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            await ctx.bot.pin_chat_message(
                chat_id=chat_id,
                message_id=message_id,
                disable_notification=disable_notification,
            )
            result = OkResult(ok=True)
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = OkResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "pin_message",
                {"chat_id": chat_id, "message_id": message_id},
                result.ok,
                result.error,
            )
        return result
  • Conditional registration of pin_message tool within register_messaging_tools(). Checks if 'pin_message' is in the allowed_tools set before decorating with @mcp.tool.
    if allowed_tools is None or "pin_message" in allowed_tools:
    
        @mcp.tool
        async def pin_message(
            chat_id: int,
            message_id: int,
            disable_notification: bool = False,
        ) -> OkResult:
            """Pin a message in a chat."""
            if not ctx.is_chat_allowed(chat_id):
                result = OkResult(ok=False, error=f"Chat {chat_id} is not allowed.")
                if ctx.audit_logger:
                    ctx.audit_logger.log(
                        "pin_message",
                        {"chat_id": chat_id, "message_id": message_id},
                        result.ok,
                        result.error,
                    )
                return result
    
            try:
                if ctx.rate_limiter:
                    await ctx.rate_limiter.acquire()
                await ctx.bot.pin_chat_message(
                    chat_id=chat_id,
                    message_id=message_id,
                    disable_notification=disable_notification,
                )
                result = OkResult(ok=True)
            except (TelegramBadRequest, TelegramForbiddenError) as exc:
                result = OkResult(ok=False, error=str(exc))
    
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "pin_message",
                    {"chat_id": chat_id, "message_id": message_id},
                    result.ok,
                    result.error,
                )
            return result
  • OkResult model – the return type for pin_message. Extends ToolResponse with just ok/error fields.
    class OkResult(ToolResponse):
        """Result for tools that return only ok/error (delete, pin, etc.)."""
    
        pass
  • is_chat_allowed helper used by pin_message to verify the chat_id is in the whitelist.
    def is_chat_allowed(self, chat_id: int) -> bool:
        """Return whether the MCP server may act on a chat."""
        if self.allowed_chat_ids is None:
            return True
        return chat_id in self.allowed_chat_ids
  • Top-level registration in AiogramMCP._register_tools() which calls register_messaging_tools() with the allowed_tools set derived from permission level.
    def _register_tools(self) -> None:
        at = self._allowed_tools
        register_messaging_tools(self._mcp, self._ctx, allowed_tools=at)
Behavior2/5

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

No annotations exist, so the description must bear the burden. It does not disclose important behavioral traits such as whether pinning replaces an existing pin, whether it is reversible, or what permissions are required.

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 extremely concise with a single sentence. However, it is not verbose and efficiently communicates the core action, though it may be too brief for some users.

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?

For a simple pin action, the description provides the basic purpose. However, it lacks details on return values (output schema exists but not shown), error conditions, and behavioral constraints, making it minimally adequate.

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

Parameters2/5

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

The input schema has 0% description coverage. The tool description adds no meaning to the parameters (chat_id, message_id, disable_notification). While names are somewhat self-explanatory, the description should at least mention the optional parameter's function.

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

Purpose4/5

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

The description clearly states the action (pin) and the resource (message in a chat). It distinguishes from sibling tools like delete_message, send_message, etc., as pinning is a distinct operation.

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 is provided on when to use this tool or when to consider alternatives. For example, it does not mention that only one message can be pinned at a time or that you need appropriate permissions.

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