get_account_details
Retrieve comprehensive account information from Brex, including balances, transactions, and financial data, to monitor business finances and analyze spending patterns.
Instructions
Get detailed information about a Brex account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | ID of the Brex account |
Implementation Reference
- src/tools/getAccountDetails.ts:50-103 (handler)The core handler function that registers and executes the get_account_details tool logic: validates input parameters, fetches account details from Brex API, optionally enriches with recent transactions, and returns formatted JSON response.registerToolHandler("get_account_details", async (request: ToolCallRequest) => { try { // Validate parameters const params = validateParams(request.params.arguments as unknown as Record<string, unknown>); logDebug(`Getting account details for account ${params.accountId}`); // Get Brex client const brexClient = getBrexClient(); try { // Call Brex API to get account details const account = await brexClient.getAccount(params.accountId); // Validate account data if (!isBrexAccount(account)) { throw new Error("Invalid account data received from Brex API"); } // Get additional account information if available try { const transactions = await brexClient.getTransactions(params.accountId, undefined, 5); const recentActivity = transactions.items.slice(0, 5); // Combine account details with recent activity const enrichedAccount = { ...account, recent_activity: recentActivity }; return { content: [{ type: "text", text: JSON.stringify(enrichedAccount, null, 2) }] }; } catch (transactionError) { // If we can't get transactions, just return the account details logError(`Error fetching recent transactions: ${transactionError instanceof Error ? transactionError.message : String(transactionError)}`); return { content: [{ type: "text", text: JSON.stringify(account, null, 2) }] }; } } catch (apiError) { logError(`Error calling Brex API: ${apiError instanceof Error ? apiError.message : String(apiError)}`); throw new Error(`Failed to get account details: ${apiError instanceof Error ? apiError.message : String(apiError)}`); } } catch (error) { logError(`Error in get_account_details tool: ${error instanceof Error ? error.message : String(error)}`); throw error; } });
- src/tools/index.ts:286-297 (schema)MCP tool schema definition including name, description, and input schema for get_account_details, used in the list tools handler.name: "get_account_details", description: "Get detailed information about a Brex account", inputSchema: { type: "object", properties: { accountId: { type: "string", description: "ID of the Brex account" } }, required: ["accountId"] }
- src/tools/getAccountDetails.ts:49-104 (registration)Registers the get_account_details tool handler using registerToolHandler from index.ts.export function registerGetAccountDetails(_server: Server): void { registerToolHandler("get_account_details", async (request: ToolCallRequest) => { try { // Validate parameters const params = validateParams(request.params.arguments as unknown as Record<string, unknown>); logDebug(`Getting account details for account ${params.accountId}`); // Get Brex client const brexClient = getBrexClient(); try { // Call Brex API to get account details const account = await brexClient.getAccount(params.accountId); // Validate account data if (!isBrexAccount(account)) { throw new Error("Invalid account data received from Brex API"); } // Get additional account information if available try { const transactions = await brexClient.getTransactions(params.accountId, undefined, 5); const recentActivity = transactions.items.slice(0, 5); // Combine account details with recent activity const enrichedAccount = { ...account, recent_activity: recentActivity }; return { content: [{ type: "text", text: JSON.stringify(enrichedAccount, null, 2) }] }; } catch (transactionError) { // If we can't get transactions, just return the account details logError(`Error fetching recent transactions: ${transactionError instanceof Error ? transactionError.message : String(transactionError)}`); return { content: [{ type: "text", text: JSON.stringify(account, null, 2) }] }; } } catch (apiError) { logError(`Error calling Brex API: ${apiError instanceof Error ? apiError.message : String(apiError)}`); throw new Error(`Failed to get account details: ${apiError instanceof Error ? apiError.message : String(apiError)}`); } } catch (error) { logError(`Error in get_account_details tool: ${error instanceof Error ? error.message : String(error)}`); throw error; } }); }
- src/tools/index.ts:47-47 (registration)Calls registerGetAccountDetails to include the tool in the overall tools registration during server setup.registerGetAccountDetails(server);
- src/tools/getAccountDetails.ts:31-43 (helper)Validates and types the input parameters for the get_account_details tool, ensuring accountId is present.function validateParams(input: any): GetAccountDetailsParams { if (!input) { throw new Error("Missing parameters"); } if (!input.accountId) { throw new Error("Missing required parameter: accountId"); } return { accountId: input.accountId }; }