Skip to main content
Glama

instagram_complete_2fa

Complete Instagram login by entering the 2FA verification code received via SMS or authenticator app after initial login requires verification.

Instructions

Complete Instagram login by providing the 2FA verification code. Use this after 'instagram_login' indicates 2FA is required.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
verification_codeYesThe 2FA verification code received via SMS or from your authenticator app

Implementation Reference

  • The `execute` method in `Complete2FATool` class performs the core logic: validates the 2FA code, checks for pending login, calls `igpapiClient.completeTwoFactorLogin`, confirms with user info, and returns success message or handles errors.
    async execute(args: { verification_code: string }): Promise<ToolResult> { const { verification_code } = args; // Validate input if (!verification_code || verification_code.trim().length === 0) { throw new Error("Verification code is required"); } // Check if there's a pending 2FA login if (!igpapiClient.hasPendingTwoFactor()) { throw new Error( "No pending 2FA login found. Please call 'instagram_login' first to initiate the login process." ); } const twoFactorInfo = igpapiClient.getTwoFactorInfo(); if (!twoFactorInfo) { throw new Error("2FA information not available. Please try logging in again."); } try { // Complete 2FA login await igpapiClient.completeTwoFactorLogin(verification_code.trim()); // Get user info to confirm login const user = await igpapiClient.getCurrentUser(); const methodName = twoFactorInfo.verificationMethod === "1" ? "SMS" : "TOTP"; return { content: [ { type: "text", text: `Successfully completed 2FA login to Instagram!\n\nAccount: ${user.username}\nFull Name: ${user.full_name || "N/A"}\nUser ID: ${user.pk}\n2FA Method: ${methodName}\n\nSession has been saved and will persist across server restarts.`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); // Check for common 2FA errors if (errorMessage.includes("code") || errorMessage.includes("verification")) { throw new Error( `Invalid verification code. Please check the code and try again. If the code expired, please call 'instagram_login' again to receive a new code.` ); } throw error; } }
  • The `getDefinition` method defines the tool's name, description, and input schema requiring 'verification_code' string.
    getDefinition(): ToolDefinition { return { name: "instagram_complete_2fa", description: "Complete Instagram login by providing the 2FA verification code. Use this after 'instagram_login' indicates 2FA is required.", inputSchema: { type: "object", properties: { verification_code: { type: "string", description: "The 2FA verification code received via SMS or from your authenticator app", }, }, required: ["verification_code"], }, }; }
  • Instantiation of Complete2FATool and inclusion in the `tools` array used by `getAllToolDefinitions()` and `executeTool()`.
    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/server.ts:59-69 (registration)
    MCP server handler for listing tools, which includes 'instagram_complete_2fa' via `getAllToolDefinitions()`.
    server.setRequestHandler(ListToolsRequestSchema, async () => { const toolDefinitions = getAllToolDefinitions(); return { tools: toolDefinitions.map((def) => ({ name: def.name, description: def.description, inputSchema: def.inputSchema, })), }; });
  • src/server.ts:71-80 (registration)
    MCP server handler for calling tools by name, executing 'instagram_complete_2fa' via `executeTool()`.
    server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const result = await executeTool(name, args || {}); return { content: result.content, isError: result.isError, }; });

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