telegram_api_login
Access Telegram channels and groups by logging in with API credentials to enable data scraping and interaction through the Telegram MCP Server.
Instructions
Login to Telegram using API credentials for fast, efficient scraping
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_hash | No | Your Telegram API Hash | |
| api_id | No | Your Telegram API ID (get from https://my.telegram.org) |
Input Schema (JSON Schema)
{
"properties": {
"api_hash": {
"description": "Your Telegram API Hash",
"type": "string"
},
"api_id": {
"description": "Your Telegram API ID (get from https://my.telegram.org)",
"type": "string"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- src/server-api-handlers.ts:7-61 (handler)Executes the telegram_api_login tool by parsing API credentials from args or environment, initializing a TelegramApiScraper instance, storing it for reuse, and returning success or 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:95-96 (registration)Switch case in the tool call handler that dispatches 'telegram_api_login' calls to this.handleApiLogin.case 'telegram_api_login': return await this.handleApiLogin(args);
- src/server.ts:291-308 (schema)Input schema and metadata for the telegram_api_login tool in the list of available tools.{ 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:763-763 (registration)Binds the handleApiLogin method from apiHandlers to the server instance.private handleApiLogin = apiHandlers.handleApiLogin.bind(this);