Skip to main content
Glama

api_search_channel

Search for specific messages within a Telegram channel by entering a channel URL and query. Retrieve relevant results with customizable limits for efficient data extraction.

Instructions

Search for messages within a Telegram channel

Input Schema

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

Implementation Reference

  • The core handler function for the 'api_search_channel' tool. It validates API connection, extracts parameters (channel URL, query, limit), calls the scraper's search method, formats the results using MarkdownFormatter, and returns them in the MCP content format.
    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'}` }] }; } },
  • The input schema definition for the 'api_search_channel' tool, specifying parameters like url, query (required), and optional limit. This is part of the tools list returned by getTools() for MCP tool discovery and 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)
    Registration in the tool dispatch switch statement within the CallToolRequestSchema handler. Routes calls to 'api_search_channel' to the bound handleApiSearchChannel method.
    case 'api_search_channel': return await this.handleApiSearchChannel(args);
  • src/server.ts:765-765 (registration)
    Binding of the handler method from apiHandlers to the server instance, enabling 'this._apiScraper' access in the handler.
    private handleApiSearchChannel = apiHandlers.handleApiSearchChannel.bind(this);
  • src/server.ts:15-15 (registration)
    Import of apiHandlers module containing the 'handleApiSearchChannel' implementation.
    import { apiHandlers } from './server-api-handlers.js';

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/DLHellMe/telegram-mcp-server'

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