fidelity_submit_2fa
Submit the SMS 2FA code received on your phone to complete Fidelity login, used when the initial login requires two-factor authentication.
Instructions
Submit the SMS 2FA code received on your phone to complete Fidelity login. Only use this after fidelity_login returns needsSms2FA=true.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The 6-digit SMS verification code. |
Implementation Reference
- src/index.ts:101-131 (registration)Registers the 'fidelity_submit_2fa' tool on the MCP server with a Zod schema that expects a single 'code' string parameter. Delegates execution to the imported submit2FACode function from auth.ts.
server.tool( "fidelity_submit_2fa", "Submit the SMS 2FA code received on your phone to complete Fidelity login. Only use this after fidelity_login returns needsSms2FA=true.", { code: z.string().describe("The 6-digit SMS verification code."), }, async ({ code }) => { try { const result = await submit2FACode(code); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; } catch (e) { return { content: [ { type: "text", text: `2FA submission failed: ${e instanceof Error ? e.message : String(e)}`, }, ], isError: true, }; } } ); - src/auth.ts:215-255 (handler)The core handler for submitting the SMS 2FA code. Gets the current browser page, fills the 6-digit code into the input field (placeholder 'XXXXXX'), optionally checks the 'Don't ask me again' checkbox, clicks Submit, then waits for redirect to the portfolio summary page.
export async function submit2FACode(code: string): Promise<LoginResult> { const { getPage } = await import("./browser.js"); const page = await getPage(); try { const codeInput = page.getByPlaceholder("XXXXXX"); await codeInput.fill(code); // Check "Don't ask me again" try { const rememberLabel = page .locator("label") .filter({ hasText: "Don't ask me again on this" }); if (await rememberLabel.isVisible()) { await rememberLabel.click(); } } catch { // Optional } // Click Submit await page.getByRole("button", { name: "Submit" }).click(); // Wait for redirect to summary await page.waitForURL("**/portfolio/summary", { timeout: 30000 }); await waitForLoadingComplete(page); await saveSession(); return { success: true, needsSms2FA: false, message: "2FA verification successful. Login complete.", }; } catch (e) { return { success: false, needsSms2FA: false, message: `2FA submission failed: ${e instanceof Error ? e.message : String(e)}`, }; } } - src/types.ts:71-75 (schema)Defines the LoginResult interface returned by submit2FACode, containing success (boolean), needsSms2FA (boolean), and message (string).
export interface LoginResult { success: boolean; needsSms2FA: boolean; message: string; } - src/index.ts:5-10 (helper)Import statement that brings the submit2FACode function from auth.ts into the tool registration file.
import { login, submit2FACode } from "./auth.js"; import { getAccountList, transfer } from "./accounts.js"; import { getPositions } from "./positions.js"; import { getQuote, placeOrder, placeBatchOrders } from "./trading.js"; import { closeBrowser, getPage, isBrowserReady, saveSession } from "./browser.js"; import type { FidelityConfig } from "./types.js";