instagram_complete_2fa
Complete Instagram login by entering the two-factor authentication code received via SMS or authenticator app after initial login attempt.
Instructions
Complete Instagram login by providing the 2FA verification code. Use this after 'instagram_login' indicates 2FA is required.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| verification_code | Yes | The 2FA verification code received via SMS or from your authenticator app |
Implementation Reference
- src/tools/complete_2fa.ts:28-77 (handler)The async execute method implements the core logic of the 'instagram_complete_2fa' tool: validates the verification code, checks for pending 2FA, calls igpapiClient.completeTwoFactorLogin, confirms with getCurrentUser, and handles errors appropriately.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; } }
- src/tools/complete_2fa.ts:12-26 (schema)The getDefinition method returns the tool schema, including name, description, and inputSchema requiring 'verification_code' string.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"], }, }; }
- src/tools/index.ts:18-28 (registration)The Complete2FATool is instantiated (line 20) and added to the central tools array used for registration and execution dispatching.const tools: BaseTool[] = [ new LoginTool(), new Complete2FATool(), new SearchAccountsTool(), new LogoutTool(), new GetUserProfileTool(), new GetCurrentUserProfileTool(), new GetUserPostsTool(), new LikePostTool(), // Add more tools here as you create them ];
- src/tools/index.ts:8-8 (registration)Import of the Complete2FATool class necessary for its registration.import { Complete2FATool } from "./complete_2fa.js";