Skip to main content
Glama

Search Telegram messages

telegram_search_messages
Read-onlyIdempotent

Find a topic, decision, link or mention in available Telegram messages. Archive search covers text, captions and saved transcripts, with all terms required and a prefix match on the last word. Connected Session uses Telegram cloud search; it does not search bot-archive transcripts for extra matches, although returned media may include a ready archive transcript. Neither path searches attachment bytes or filenames. Use a few distinctive words, not a full natural-language question. To search a person's or channel's conversation, resolve its name/@username/link with telegram_find_chat and pass chat_id; query searches message content, not contact names. For a name lookup miss, follow telegram_find_chat guidance: try at most 3 untried name variants before asking for an exact reference. Confirm candidates found via a changed name before reading history or sending. Default 30 matches; archive maximum 200, Session maximum 50. Read effective_limit, source, coverage and partial; a full page is not an exhaustive search. Use since inclusively and before exclusively for a precise date interval. When has_more=true, pass next_cursor as cursor with the same query, chat_id and date filters to continue. Never construct or edit cursors. A repeated query without cursor starts again. Request another page only when needed for the user's question; stop when enough context is found, has_more=false, or a cursor fails/makes no progress. A filtered Session page can be empty with continuation; has_more means continuation is available, not guaranteed visible matches. Cursors expire after 15 minutes and may expire on restart or cache eviction: explain and restart explicitly, never claim complete history. Search reflects changing live data, not a fixed snapshot. For a conversation summary use telegram_get_messages. Use the user's known timezone; if unknown, silently use UTC without asking or adding a timezone caveat. Do not infer it from language. For calendar days pass since at inclusive midnight and before at the exclusive next midnight as ISO 8601 timestamps with the correct offsets; distinguish calendar days from rolling 24h windows. Do not silently broaden the requested period. Distinguish errors from successful zero matches. Read empty_reason, chat_found, history_notice and setup_required when present. chat_not_in_archive means this ID is absent from the saved archive, not from Telegram: resolve the chat again and follow telegram_find_chat recovery guidance. For no_matches, consider fewer distinctive words and verify the intended chat/time range; no_searchable_terms needs a word or number. Do not loop on unchanged searches or claim the conversation never happened. For limited archive history, explain the returned coverage; /import in https://t.me/lemma_telepath_bot supports older exported history. Never ask for login codes/passwords here. Do not prescribe reconnection from zero matches alone or reconnect a working Session. Errors need the reported cause and an appropriate next step; respect retry delays and never call a timeout missing history or lost permission. If unknown, say so and offer support at https://t.me/hellolemma. Use telegram_get_file with returned chat_id/message_id to read supported archive or Session attachments; photos use telegram_get_photo. Messages include is_forwarded and forward_origin (original author/channel and Unix date when available). For forwards, from identifies who forwarded it in this chat, not the original author. Missing origin data does not prove authorship; never infer a hidden author's identity. Use an already connected Session where supported; preserve source, coverage and actual errors. Do not suggest connecting or reconnecting Session unless the user explicitly asks for Session setup. Never switch sender automatically or request login codes/passwords in chat.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "query": "<query>"
    },
    "name": "telegram_search_messages"
  }
}

Input Schema

NameRequiredDescriptionDefault
limitNoPage size. Default 30; archive maximum 200, Session maximum 50. Use next_cursor to continue when has_more is true.
queryYesDistinctive words in message content, not a contact lookup. Session supports up to 200 characters.
sinceNoOnly messages at or after this time. Accepts an ISO 8601 timestamp, unix seconds, 'today', 'yesterday', or a relative window like '24h' / '7d'.
beforeNoOnly messages strictly older than this time; exclusive end of the search interval. Accepts an ISO 8601 timestamp, unix seconds, 'today', 'yesterday', or a relative window like '24h' / '7d'.
cursorNoOpaque next_cursor from the preceding search page. Keep query, chat_id, since and before unchanged; do not invent a cursor.
chat_idNoRestrict to this chat, resolved with telegram_find_chat.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changed
    • addedInput schema / properties / before
      Added value: +{
      +  "description": "Only messages strictly older than this time; exclusive end of the search interval. Accepts an ISO 8601 timestamp, unix seconds, 'today', 'yesterday', or a relative window like '24h' / '7d'.",
      +  "type": "string"
      +}
    • addedInput schema / properties / cursor
      Added value: +{
      +  "description": "Opaque next_cursor from the preceding search page. Keep query, chat_id, since and before unchanged; do not invent a cursor.",
      +  "maxLength": 4096,
      +  "minLength": 1,
      +  "type": "string"
      +}
    • changedInput schema / properties / limit / description
      Previous value: -"How many matches to return. Default 30; archive maximum 200, Session maximum 50. This tool currently has no pagination."New value: +"Page size. Default 30; archive maximum 200, Session maximum 50. Use next_cursor to continue when has_more is true."
  2. Changed3 schema fields changed
    • changedInput schema / properties / chat_id / description
      Previous value: -"Restrict the search to this chat."New value: +"Restrict to this chat, resolved with telegram_find_chat."
    • changedInput schema / properties / limit / description
      Previous value: -"How many matches to return. Default 30."New value: +"How many matches to return. Default 30; archive maximum 200, Session maximum 50. This tool currently has no pagination."
    • changedInput schema / properties / query / description
      Previous value: -"Words to search for."New value: +"Distinctive words in message content, not a contact lookup. Session supports up to 200 characters."
  3. First observed

TDQS

A4.5/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true, openWorldHint=true, idempotentHint=true, and destructiveHint=false, so the safety profile is covered. The description adds substantial behavioral context beyond annotations: archive versus Session coverage, cursor expiry after 15 minutes, live-data behavior, empty-page-with-continuation semantics, and error fields such as empty_reason and chat_found. It is very rich, though some operational policy is repeated.

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 front-loaded with purpose and key distinctions, but it is very long for a search tool and contains repeated operational warnings about login codes, Session reconnection, and not claiming complete history. The density of edge-case guidance is useful, but the length and repetition reduce conciseness.

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?

Given the tool's complexity, multiple search backends, pagination, date filtering, and error states, the description is highly complete. It explains return fields such as effective_limit, source, coverage, partial, has_more, and next_cursor even though no output schema exists, and it covers recovery guidance for common failure modes.

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

Parameters4/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 still adds meaning beyond the schema by clarifying that query searches message content rather than contact names, that since is inclusive and before is exclusive, that cursors must not be constructed or edited, and that chat_id should come from telegram_find_chat.

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 opens with a specific verb and resource: 'Find a topic, decision, link or mention in available Telegram messages.' It explicitly distinguishes archive search from Connected Session cloud search and names sibling tools for conversation summaries, chat resolution, and attachment reading. An agent can identify the tool's scope without opening the schema.

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?

It gives extensive when-to-use guidance: use a few distinctive words rather than a natural-language question, resolve chat names with telegram_find_chat, use telegram_get_messages for conversation summaries, and use telegram_get_file or telegram_get_photo for attachments. It also explains pagination continuation, date interval semantics, and when to stop paging.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources