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
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of results | |
| query | Yes | Search query | |
| url | Yes | The Telegram channel URL |
Implementation Reference
- src/server-api-handlers.ts:158-201 (handler)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'}` }] }; } },
- src/server.ts:336-358 (schema)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';