Skip to main content
Glama
DLHellMe

Telegram MCP Server

by DLHellMe

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
NameRequiredDescriptionDefault
api_idNoYour Telegram API ID (get from https://my.telegram.org)
api_hashNoYour Telegram API Hash

Implementation Reference

  • 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`
            }]
          };
        }
      },
  • 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);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.7/5.0
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden for disclosing behavior. It only says 'Login' and 'fast, efficient scraping', providing no information about session persistence, authentication checks, rate limits, error handling, or the effect of repeated logins. The tool's behavior is entirely opaque.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence that clearly states the action. It is concise, though the phrase 'fast, efficient scraping' adds a subjective flourish without functional value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

As a login tool with no output schema and no annotations, the description fails to explain what happens on success/failure, what the returned data looks like, or why both parameters are optional. It is incomplete for an agent to confidently invoke and interpret the result.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both api_id and api_hash having descriptions. The tool description itself adds nothing beyond the schema, so the baseline of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool logs into Telegram using API credentials, which is a specific verb+resource action. It distinguishes somewhat from sibling tools like telegram_login by emphasizing 'API credentials', but doesn't fully disambiguate between the two login-related tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus telegram_login or other authentication tools. The phrase 'for scraping' implies a use case, but there is no explicit when-to-use or when-not-to-use guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.