Skip to main content
Glama
DLHellMe

Telegram MCP Server

by DLHellMe

api_search_channel

Search for messages within a Telegram channel using specific queries to find relevant content quickly.

Instructions

Search for messages within a Telegram channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe Telegram channel URL
queryYesSearch query
limitNoMaximum number of results

Implementation Reference

  • The main handler function that checks API connection, extracts parameters (channel URL, query, limit), calls the scraper's search method, formats results with MarkdownFormatter, and returns the search results or error messages.
    async handleApiSearchChannel(this: any, args: any): Promise<any> {
      if (!this._apiScraper || !this._apiScraper.isConnected()) {
        return {
          content: [{
            type: 'text',
            text: '❌ Not connected to Telegram API. Please use telegram_api_login first.'
          }]
        };
      }
      
      try {
        const channelUrl = args.url || args.channel;
        const query = args.query || args.search || '';
        const limit = args.limit || 1000;
        
        if (!query) {
          return {
            content: [{
              type: 'text',
              text: '❌ Please provide a search query'
            }]
          };
        }
        
        const result = await this._apiScraper.search(channelUrl, query, limit);
        
        const formatter = new (await import('./formatters/markdown-formatter.js')).MarkdownFormatter();
        const markdown = formatter.format(result);
        
        return {
          content: [{
            type: 'text',
            text: `# Search Results for "${query}"\n\n${markdown}\n\n✅ Searched using Telegram API`
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `❌ Search failed: ${error instanceof Error ? error.message : 'Unknown error'}`
          }]
        };
      }
    },
  • src/server.ts:337-358 (registration)
    Registers the 'api_search_channel' tool in the MCP server's tool list, including its description and input schema for validation.
      name: 'api_search_channel',
      description: 'Search for messages within a Telegram channel',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'The Telegram channel URL'
          },
          query: {
            type: 'string',
            description: 'Search query'
          },
          limit: {
            type: 'number',
            description: 'Maximum number of results',
            default: 50
          }
        },
        required: ['url', 'query']
      }
    },
  • src/server.ts:101-102 (registration)
    Dispatches tool calls to the appropriate handler in the main request handler switch statement.
    case 'api_search_channel':
      return await this.handleApiSearchChannel(args);
  • src/server.ts:765-765 (registration)
    Binds the handler from apiHandlers to the server instance for use in tool dispatching.
    private handleApiSearchChannel = apiHandlers.handleApiSearchChannel.bind(this);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are present, so the description must disclose behavioral traits. It does not mention authentication requirements, rate limits, return format, or any side effects. The only implicit behavior is that it performs a read-only search.

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 very short and to the point, with no unnecessary words. However, it is so minimal that it sacrifices substance for brevity, though it remains a single clear sentence.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description should explain what the search returns and when to use it. It does neither. The description is sufficient for a basic understanding but lacks critical context for an AI agent to select it correctly among many similar tools.

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?

The input schema fully describes the parameters (url, query, limit), so the description adds no additional meaning. The baseline score of 3 applies, and the description does not elaborate on query syntax or url format.

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 (search) and target (messages within a Telegram channel), which distinguishes it from scraping or info tools. However, it could be more explicit about the scope (e.g., search across all messages in the channel) and does not mention any limitations.

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 about when to use this tool instead of siblings like scrape_channel or api_scrape_channel. The description only states the action, leaving the agent to infer usage context.

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