get_2fa_code
Retrieve the current two-factor authentication (2FA) code for a specific username and website, enabling automated login processes while maintaining security.
Instructions
Retrieve the current 2FA code for a username when logging into a website.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username or email of the account you need to login, e.g. "john.doe@example.com" | |
| website | Yes | The domain name of the website you need to login, e.g. "github.com" |
Implementation Reference
- src/authenticator.ts:37-51 (handler)Core handler function that fetches the 2FA code from the backend API via HTTP request using the access token.async get2FACode(website: string, username: string): Promise<Get2FACodeResponse> { const url = `${this.baseUrl}/code?website=${encodeURIComponent(website)}&username=${encodeURIComponent(username)}`; const response = await fetch(url, { headers: { Authorization: `Bearer ${this.accessToken}`, }, }); if (!response.ok) { const errorBody = await response.text(); console.error(`HTTP error ${response.status} from ${url}: ${errorBody}`); throw new Error(`HTTP error ${response.status}: ${errorBody}`); // Include body in error } return (await response.json()) as Get2FACodeResponse; }
- src/mcp.ts:26-50 (registration)Registers the get_2fa_code tool with the MCP server, including input schema and thin wrapper handler that delegates to Authenticator.get2FACode and formats the MCP response.this.tool( 'get_2fa_code', 'Retrieve the current 2FA code for a username when logging into a website.', { website: z .string() .describe('The domain name of the website you need to login, e.g. "github.com"'), username: z .string() .describe( 'The username or email of the account you need to login, e.g. "john.doe@example.com"' ), }, async ({ website, username }, extra) => { const res = await this.authenticator.get2FACode(website, username); return { content: [ { type: 'text', text: `The 2FA code is ${res.code}, it will expire in ${res.valid_for} seconds.`, }, ], }; } );
- src/mcp.ts:29-38 (schema)Zod schema for the tool inputs: website (string) and username (string) with descriptions.{ website: z .string() .describe('The domain name of the website you need to login, e.g. "github.com"'), username: z .string() .describe( 'The username or email of the account you need to login, e.g. "john.doe@example.com"' ), },
- src/authenticator.ts:2-27 (schema)TypeScript interfaces defining input parameters and output responses for the authenticator methods, including get2FACode.interface Get2FACodeParams { website: string; username: string; } interface GetPasswordParams { website: string; username: string; } interface GetAccountListParams { website: string; } export interface Get2FACodeResponse { code: string; valid_for: number; } export interface GetPasswordResponse { password: string; } export interface GetAccountListResponse { accounts: string[]; }