Skip to main content
Glama
aggeentik

Telegram Bot MCP Server

by aggeentik

telegram_search_messages

Read-onlyIdempotent

Search cached Telegram channel messages using a text query, with pagination and response format options. Returns matching messages from the current server session cache only.

Instructions

Search for messages in a Telegram channel (from local cache ONLY).

⚠️ CRITICAL LIMITATIONS - READ CAREFULLY:

  1. Session-Only Cache: This tool ONLY searches messages cached in the CURRENT SERVER SESSION.

    • Messages published/edited BEFORE the server started are NOT available

    • Cache is CLEARED when the server restarts

    • This is a Telegram Bot API limitation, not a bug

  2. Cannot Retrieve Historical Messages: The Telegram Bot API does not provide methods to fetch arbitrary messages or search message history.

  3. What IS Cached: ✅ Messages published via publish_message in current session ✅ Messages edited via edit_message in current session ✅ Photos published via publish_photo in current session ✅ Photo captions edited via edit_message_caption in current session

  4. What is NOT Cached: ❌ Messages sent before server started ❌ Messages sent by other bots or users ❌ Messages sent when server was offline

  5. You CAN Still: ✅ Edit messages from previous sessions if you have the message_id ✅ Delete messages from previous sessions if you have the message_id ✅ The message_id is returned when publishing messages - store it if needed later!

Args: channel_id: Channel username (e.g., '@mychannel') or numeric chat ID to search in. query: Search query string. Performs case-insensitive search in message text/caption. If None or empty, returns all cached messages for the channel. limit: Maximum number of results to return. Default is 10. Results are sorted by date (newest first). offset: Number of results to skip. Use for pagination. Default is 0. response_format: Response format. Options: 'json' for structured data, 'markdown' for human-readable text. Default is 'markdown'.

Returns: A dictionary containing: - messages: List of matching messages (may be empty if nothing cached) - count: Number of messages returned in this page - total: Total number of matching messages in cache - offset: Current offset value - limit: Current limit value - has_more: Boolean indicating if more results are available - next_offset: Offset value for the next page (if has_more is True) - query: The search query used - channel_id: The channel searched - status: Operation status If response_format='markdown', returns formatted text content.

Note: If you need to work with older messages, you must keep track of message_id values returned when publishing. There is no way to retrieve message_id for historical messages through the Telegram Bot API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
queryNo
offsetNo
channel_idYes
response_formatNomarkdown

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

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

The description discloses extensive behavioral traits: session-only cache, cache clearing on restart, Bot API limitations, what is/isn't cached, and the ability to edit/delete with message_id. This goes far beyond the annotations, which only indicate read-only and idempotent.

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?

Although lengthy, the description is well-structured with bolded warnings, bullet points, and dedicated sections for Args, Returns, and Notes. Every sentence provides actionable information, and the critical limitations are front-loaded.

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

Completeness5/5

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

The description covers all aspects: purpose, limitations, usage, parameters, return values, and practical notes. It is complete for a tool with complex caching constraints, and the output schema is described in sufficient detail.

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

Parameters5/5

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

Despite the schema having 0% description coverage, the description thoroughly explains every parameter: channel_id, query (case-insensitive, None/empty returns all), limit, offset (pagination), and response_format (json/markdown). This adds essential meaning beyond the schema.

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 begins with 'Search for messages in a Telegram channel (from local cache ONLY)' which is a specific verb+resource+scope. It clearly distinguishes this tool from siblings by emphasizing the local cache limitation and stating it cannot retrieve historical messages.

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 explicitly states when to use the tool (only for session-cached messages) and when not to (historical messages). It references sibling tools like publish_message and edit_message, and advises storing message_id for later operations, providing clear usage context.

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/aggeentik/telegram-bot-mcp'

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