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