telegram_api_login
Authenticate with Telegram using API credentials to enable data collection and interaction through the Telegram MCP Server.
Instructions
Login to Telegram using API credentials for fast, efficient scraping
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_id | No | Your Telegram API ID (get from https://my.telegram.org) | |
| api_hash | No | Your Telegram API Hash |
Implementation Reference
- src/server-api-handlers.ts:7-61 (handler)The handler function for 'telegram_api_login' that initializes TelegramApiScraper with API credentials (from args or env), performs login, stores the scraper instance, and returns success/error messages.async handleApiLogin(this: any, args: any): Promise<any> { try { // Get API credentials from environment or args const apiId = parseInt(process.env.TELEGRAM_API_ID || args.api_id || '0'); const apiHash = process.env.TELEGRAM_API_HASH || args.api_hash || ''; if (!apiId || !apiHash) { return { content: [{ type: 'text', text: `❌ API credentials not provided. Please either: 1. Set environment variables TELEGRAM_API_ID and TELEGRAM_API_HASH 2. Pass api_id and api_hash as parameters 3. See API_SETUP.md for instructions on getting your API credentials from https://my.telegram.org` }] }; } const config: TelegramApiConfig = { apiId, apiHash }; const scraper = new TelegramApiScraper(config); await scraper.initialize(); // Store the scraper instance for reuse this._apiScraper = scraper; return { content: [{ type: 'text', text: `✅ Successfully authenticated with Telegram API! You can now use the API-based tools: - api_scrape_channel - Fast channel scraping - api_search_channel - Search within channels - api_get_channel_info - Get channel details Your session has been saved for future use.` }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ API authentication failed: ${error instanceof Error ? error.message : 'Unknown error'} Please check: - Your API credentials are correct - Your phone number includes country code (e.g., +1234567890) - You entered the verification code correctly` }] }; } },
- src/server.ts:291-308 (schema)The MCP tool schema definition including name, description, and input schema for api_id and api_hash parameters.{ name: 'telegram_api_login', description: 'Login to Telegram using API credentials for fast, efficient scraping', inputSchema: { type: 'object', properties: { api_id: { type: 'string', description: 'Your Telegram API ID (get from https://my.telegram.org)' }, api_hash: { type: 'string', description: 'Your Telegram API Hash' } }, required: [] } },
- src/server.ts:95-96 (registration)The dispatch case in the tool call handler that routes 'telegram_api_login' calls to the handleApiLogin method.case 'telegram_api_login': return await this.handleApiLogin(args);
- src/server.ts:763-763 (registration)The method binding that connects the server instance to the apiHandlers.handleApiLogin function.private handleApiLogin = apiHandlers.handleApiLogin.bind(this);