Skip to main content
Glama

instagram_login

Authenticate to Instagram by using stored credentials, enabling session persistence for continued access to Instagram features through the MCP server.

Instructions

Login to an Instagram account using credentials from environment variables (IG_USERNAME and IG_PASSWORD). The session will be saved and persist across server restarts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The 'execute' method in LoginTool class implements the core logic of the 'instagram_login' tool. It retrieves credentials from config, checks for existing session, performs login using igpapiClient, handles success response, and manages 2FA requirement by instructing to use complete_2fa tool.
    async execute(args: Record<string, unknown>): Promise<ToolResult> {
      // Get credentials from environment variables via config
      const config = getConfig();
      const username = config.igpapi?.username;
      const password = config.igpapi?.password;
    
      // Validate that credentials are available
      if (!username || !password) {
        throw new Error(
          "Instagram credentials not found in environment variables. " +
          "Please set IG_USERNAME and IG_PASSWORD environment variables."
        );
      }
    
      // Check if already logged in
      if (igpapiClient.isLoggedIn()) {
        try {
          const currentUser = await igpapiClient.getCurrentUser();
          return {
            content: [
              {
                type: "text",
                text: `Already logged in as: ${currentUser.username || username}\nSession is active and persistent.`,
              },
            ],
          };
        } catch {
          // Session might be invalid, continue with login
        }
      }
    
      // Initialize client if needed
      if (!igpapiClient.isInitialized()) {
        await igpapiClient.initialize();
      }
    
      try {
        // Perform login
        await igpapiClient.login(username, password);
    
        // Get user info to confirm login
        const user = await igpapiClient.getCurrentUser();
    
        return {
          content: [
            {
              type: "text",
              text: `Successfully logged in to Instagram!\n\nAccount: ${user.username}\nFull Name: ${user.full_name || "N/A"}\nUser ID: ${user.pk}\n\nSession has been saved and will persist across server restarts.`,
            },
          ],
        };
      } catch (error) {
        // Check if this is a 2FA requirement
        if (error && typeof error === "object" && "verificationMethod" in error) {
          const twoFactorInfo = error as {
            username: string;
            verificationMethod: "0" | "1";
            totpTwoFactorOn: boolean;
          };
    
          const methodName = twoFactorInfo.verificationMethod === "1" ? "SMS" : "TOTP (Authenticator App)";
          const codeSentMessage = twoFactorInfo.verificationMethod === "1" 
            ? "A verification code has been sent to your phone via SMS."
            : "Please check your authenticator app for the verification code.";
    
          return {
            content: [
              {
                type: "text",
                text: `Two-Factor Authentication (2FA) is required for this account.\n\n${codeSentMessage}\n\nVerification Method: ${methodName}\nUsername: ${twoFactorInfo.username}\n\nPlease use the 'instagram_complete_2fa' tool with the verification code to complete the login.`,
              },
            ],
            isError: false, // Not an error, just requires additional step
          };
        }
    
        // Re-throw other errors
        throw error;
      }
    }
  • The 'getDefinition' method defines the tool schema for 'instagram_login', specifying its name, description, and empty input schema (no parameters required).
    export class LoginTool extends BaseTool {
      getDefinition(): ToolDefinition {
        return {
          name: "instagram_login",
          description: "Login to an Instagram account using credentials from environment variables (IG_USERNAME and IG_PASSWORD). The session will be saved and persist across server restarts.",
          inputSchema: {
            type: "object",
            properties: {},
            required: [],
          },
        };
      }
  • The 'instagram_login' tool (LoginTool) is registered by instantiating LoginTool and adding it to the tools array, which is used by getAllToolDefinitions() for MCP server registration.
    const tools: BaseTool[] = [
      new LoginTool(),
      new Complete2FATool(),
      new SearchAccountsTool(),
      new LogoutTool(),
      new GetUserProfileTool(),
      new GetCurrentUserProfileTool(),
      new GetUserPostsTool(),
      new LikePostTool(),
      new LikeCommentTool(),
      new CommentOnPostTool(),
      new GetPostCommentsTool(),
      new GetPostDetailsTool(),
      new GetUserStoriesTool(),
      new GetTimelineFeedTool(),
      new FollowUserTool(),
      // Add more tools here as you create them
    ];
  • src/tools/index.ts:7-7 (registration)
    Import statement for LoginTool used in tool registration.
    import { LoginTool } from "./login.js";
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it uses environment variables for credentials, saves the session, and persists across server restarts. This covers authentication method, state management, and persistence, though it could add more on error handling or rate limits.

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?

The description is two sentences that are front-loaded with the core action and efficiently cover essential details (credentials source and session persistence) without any wasted words. Every sentence adds value, making it highly concise and well-structured.

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

Completeness4/5

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

Given the tool's complexity (authentication with session management), no annotations, no output schema, and 0 parameters, the description is fairly complete: it explains what the tool does, how it works, and behavioral aspects. However, it could improve by mentioning prerequisites (e.g., environment variables must be set) or potential outputs, but for a no-param tool, it's sufficient.

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?

The input schema has 0 parameters with 100% coverage, so no parameters need documentation. The description appropriately doesn't discuss parameters, and since there are none, it meets the baseline of 4 for not adding unnecessary information.

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 action ('Login to an Instagram account') and the resource ('Instagram account'), making the purpose unambiguous. However, it doesn't differentiate from sibling tools like 'instagram_complete_2fa' which might also be part of authentication flows, so it doesn't fully distinguish from alternatives.

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

Usage Guidelines3/5

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

The description implies usage by specifying that credentials come from environment variables, suggesting this tool is for initial authentication. However, it doesn't explicitly state when to use this versus alternatives like 'instagram_complete_2fa' for 2FA or provide clear exclusions, leaving some ambiguity in the authentication workflow.

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/anand-kamble/mcp-instagram'

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