Skip to main content
Glama

telegram-status

Read-only

Check whether your Telegram account is currently connected to the MCP-Telegram server.

Instructions

Check Telegram connection status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for the telegram-status tool. Checks Telegram connection status and returns user info if connected, or instructions to authenticate via QR if not connected.
    server.registerTool(
      "telegram-status",
      { description: "Check Telegram connection status", annotations: READ_ONLY },
      async () => {
        if (await telegram.ensureConnected()) {
          try {
            const me = await telegram.getMe();
            return ok(`Connected as ${me.firstName ?? ""} (@${me.username ?? "unknown"}, id: ${me.id})`);
          } catch {
            return ok("Connected, but failed to get user info");
          }
        }
    
        const reason = telegram.lastError ? ` Reason: ${telegram.lastError}` : "";
        return ok(`Not connected.${reason} Use telegram-login to authenticate via QR code.`);
      },
    );
  • Registration function registerAuthTools that registers telegram-status via server.registerTool() inside src/tools/auth.ts.
    export function registerAuthTools(server: McpServer, telegram: TelegramService) {
      server.registerTool(
        "telegram-status",
        { description: "Check Telegram connection status", annotations: READ_ONLY },
        async () => {
          if (await telegram.ensureConnected()) {
            try {
              const me = await telegram.getMe();
              return ok(`Connected as ${me.firstName ?? ""} (@${me.username ?? "unknown"}, id: ${me.id})`);
            } catch {
              return ok("Connected, but failed to get user info");
            }
          }
    
          const reason = telegram.lastError ? ` Reason: ${telegram.lastError}` : "";
          return ok(`Not connected.${reason} Use telegram-login to authenticate via QR code.`);
        },
      );
    
      server.registerTool(
        "telegram-login",
        {
          description:
            "Login to Telegram via QR code. Returns QR image. IMPORTANT: pass the entire result to user without modifications.",
          annotations: WRITE,
        },
        async () => {
          let qrDataUrl = "";
    
          const loginPromise = telegram.startQrLogin((dataUrl) => {
            qrDataUrl = dataUrl;
          });
    
          // Wait for first QR to be generated
          const startTime = Date.now();
          while (!qrDataUrl && Date.now() - startTime < 15000) {
            await new Promise((r) => setTimeout(r, 500));
          }
    
          if (!qrDataUrl) {
            return fail(new Error("Failed to generate QR code"));
          }
    
          // Login continues in background
          loginPromise.then((result) => {
            if (result.success) {
              console.error("[mcp-telegram] Login successful");
            } else {
              console.error(`[mcp-telegram] Login failed: ${result.message}`);
            }
          });
    
          // Save QR to file as fallback (no data sent to third-party services)
          const base64 = qrDataUrl.replace(/^data:image\/png;base64,/, "");
          const qrFilePath = join(telegram.sessionDir, "qr-login.png");
          await writeFile(qrFilePath, Buffer.from(base64, "base64")).catch(() => {});
    
          const instructions = [
            "Scan this QR code in Telegram: **Settings → Devices → Link Desktop Device**.",
            "",
            `If the QR image is not visible, it's also saved to: ${qrFilePath}`,
            "",
            "After scanning, run **telegram-status** to verify the connection.",
          ].join("\n");
    
          return {
            content: [
              {
                type: "image" as const,
                data: base64,
                mimeType: "image/png" as const,
              },
              {
                type: "text",
                text: instructions,
              },
            ],
          };
        },
      );
    
      server.registerTool(
        "telegram-logout",
        {
          description:
            "Log out from Telegram completely. Revokes the session on Telegram servers (removes it from Settings → Devices), deletes the local session file, and disconnects. After this you must run telegram-login to re-authenticate.",
          annotations: DESTRUCTIVE,
        },
        async () => {
          const wasConnected = await telegram.ensureConnected();
    
          if (!wasConnected && !telegram.hasLocalSession()) {
            return fail(new Error("Not logged in. Nothing to log out from."));
          }
    
          try {
            const revoked = await telegram.logOut();
            if (!wasConnected) {
              return ok("Local session removed (was already disconnected). Server-side revoke was not performed.");
            }
            if (revoked) {
              return ok("Logged out. Session revoked on Telegram servers and removed locally.");
            }
            return fail(
              new Error(
                "Local session removed, but server-side revoke could not be confirmed. Open 'Settings → Devices' in Telegram and terminate the session manually if it is still listed.",
              ),
            );
          } catch (err) {
            // Local file removal failed (read-only FS, permission denied, etc.).
            // Never claim local cleanup succeeded when the file may still be on disk.
            return fail(
              new Error(
                `Failed to remove local session file: ${err instanceof Error ? err.message : String(err)}. ` +
                  `Delete it manually (check telegram-status for the path).`,
              ),
            );
          }
        },
      );
    }
  • Schema/description for the telegram-status tool. No input parameters; just a description and READ_ONLY annotation.
    { description: "Check Telegram connection status", annotations: READ_ONLY },
  • Helper function 'ok' used by the handler to return a successful text response.
    export function ok(text: string) {
      return { content: [{ type: "text" as const, text: sanitize(text) }] };
    }
  • READ_ONLY annotation constant used in the tool's schema definition.
    export const READ_ONLY = { readOnlyHint: true, openWorldHint: true } as const;
    export const WRITE = { readOnlyHint: false, openWorldHint: true } as const;
    export const DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, openWorldHint: true } as const;
Behavior4/5

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

The description aligns with annotations (readOnlyHint=true, openWorldHint=true). It adds context about checking connection status without contradicting or adding needed behavioral details beyond what annotations already provide.

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

Conciseness5/5

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

A single, concise sentence that front-loads the purpose. Every word earns its place with no redundancy.

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

Completeness5/5

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

The description is fully adequate for a simple status check with no parameters and no output schema. It tells the agent exactly what the tool does.

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

Parameters4/5

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

With zero parameters, schema coverage is 100%. The description need not add parameter information; baseline for no parameters is 4.

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

Purpose5/5

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

The description 'Check Telegram connection status' clearly states a specific verb+resource. Among many sibling tools focused on messaging, contacts, or settings, this one uniquely indicates a connectivity check with no parameters.

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

Usage Guidelines4/5

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

The description implies usage for verifying connectivity before other actions, but does not explicitly state when to use vs alternatives. Given its simplicity and lack of parameters, the usage context is clear but no exclusions are provided.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp-telegram/mcp-telegram'

If you have feedback or need assistance with the MCP directory API, please join our Discord server