get_account_info
Retrieve account details and balances from Interactive Brokers MCP Server to manage and monitor trading accounts effectively.
Instructions
Get account information and balances
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| random_string | Yes | Dummy parameter for no-parameter tools |
Implementation Reference
- src/tool-handlers.ts:301-330 (handler)Main tool handler function that ensures gateway readiness and authentication, calls IBClient.getAccountInfo(), and formats the result as ToolHandlerResult.async getAccountInfo(input: GetAccountInfoInput): Promise<ToolHandlerResult> { try { // Ensure Gateway is ready await this.ensureGatewayReady(); // Ensure authentication in headless mode if (this.context.config.IB_HEADLESS_MODE) { await this.ensureAuth(); } const result = await this.context.ibClient.getAccountInfo(); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: this.formatError(error), }, ], }; } }
- src/tool-definitions.ts:16-18 (schema)Zod shape definition for get_account_info tool input validation, requiring a 'confirm' literal true.export const GetAccountInfoZodShape = { confirm: z.literal(true) };
- src/tools.ts:49-55 (registration)MCP server tool registration for 'get_account_info', linking schema and handler.// Register get_account_info tool server.tool( "get_account_info", "Get account information and balances. Usage: `{ \"confirm\": true }`.", GetAccountInfoZodShape, async (args) => await handlers.getAccountInfo(args) );
- src/ib-client.ts:256-300 (helper)Low-level IBClient method that fetches portfolio accounts and their summaries via API calls.async getAccountInfo(): Promise<any> { Logger.log("[ACCOUNT-INFO] Starting getAccountInfo request..."); try { Logger.log("[ACCOUNT-INFO] Fetching portfolio accounts..."); const accountsResponse = await this.client.get("/portfolio/accounts"); const accounts = accountsResponse.data; Logger.log(`[ACCOUNT-INFO] Found ${accounts?.length || 0} accounts:`, accounts); const result = { accounts: accounts, summaries: [] as any[] }; Logger.log("[ACCOUNT-INFO] Processing account summaries..."); for (let i = 0; i < accounts.length; i++) { const account = accounts[i]; Logger.log(`[ACCOUNT-INFO] Processing account ${i + 1}/${accounts.length}: ${account.id}`); const summaryResponse = await this.client.get( `/portfolio/${account.id}/summary` ); const summary = summaryResponse.data; Logger.log(`[ACCOUNT-INFO] Account ${account.id} summary:`, summary); result.summaries.push({ accountId: account.id, summary: summary }); } Logger.log(`[ACCOUNT-INFO] Completed processing ${result.summaries.length} accounts`); return result; } catch (error) { Logger.error("[ACCOUNT-INFO] Failed to get account info:", error); // Check if this is likely an authentication error if (this.isAuthenticationError(error)) { const authError = new Error("Authentication required to retrieve account information. Please authenticate with Interactive Brokers first."); (authError as any).isAuthError = true; throw authError; } throw new Error("Failed to retrieve account information"); } }