get_all_accounts
Retrieve all Brex accounts with pagination and filtering options to manage financial data efficiently.
Instructions
Get all Brex accounts with pagination support
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_all_accounts"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | Number of items per page (default: 50, max: 100) | |
| max_items | No | Maximum total number of items to retrieve across all pages | |
| status | No | Filter accounts by status |
Implementation Reference
- src/tools/getAllAccounts.ts:123-161 (handler)Main handler function that executes the get_all_accounts tool logic: validates parameters, fetches accounts using BrexClient with pagination support, handles API errors, and returns JSON-formatted results with metadata.
registerToolHandler("get_all_accounts", async (request: ToolCallRequest) => { try { // Validate parameters const params = validateParams(request.params.arguments); logDebug(`Getting all accounts with params: ${JSON.stringify(params)}`); // Get Brex client const brexClient = getBrexClient(); try { // Fetch all accounts with pagination const allAccounts = await fetchAllAccounts(brexClient, params); logDebug(`Successfully fetched ${allAccounts.length} total accounts`); // Return raw results with pagination metadata const result = { accounts: allAccounts, meta: { total_count: allAccounts.length, requested_parameters: params } }; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (apiError) { logError(`Error calling Brex API: ${apiError instanceof Error ? apiError.message : String(apiError)}`); throw new Error(`Failed to get accounts: ${apiError instanceof Error ? apiError.message : String(apiError)}`); } } catch (error) { logError(`Error in get_all_accounts tool: ${error instanceof Error ? error.message : String(error)}`); throw error; } }); - src/tools/getAllAccounts.ts:21-25 (schema)TypeScript interface defining the input parameters for the get_all_accounts tool.
interface GetAllAccountsParams { page_size?: number; max_items?: number; status?: string; } - src/tools/getAllAccounts.ts:122-162 (registration)Registration function that sets up the get_all_accounts tool handler using registerToolHandler. Called from src/tools/index.ts.
export function registerGetAllAccounts(_server: Server): void { registerToolHandler("get_all_accounts", async (request: ToolCallRequest) => { try { // Validate parameters const params = validateParams(request.params.arguments); logDebug(`Getting all accounts with params: ${JSON.stringify(params)}`); // Get Brex client const brexClient = getBrexClient(); try { // Fetch all accounts with pagination const allAccounts = await fetchAllAccounts(brexClient, params); logDebug(`Successfully fetched ${allAccounts.length} total accounts`); // Return raw results with pagination metadata const result = { accounts: allAccounts, meta: { total_count: allAccounts.length, requested_parameters: params } }; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (apiError) { logError(`Error calling Brex API: ${apiError instanceof Error ? apiError.message : String(apiError)}`); throw new Error(`Failed to get accounts: ${apiError instanceof Error ? apiError.message : String(apiError)}`); } } catch (error) { logError(`Error in get_all_accounts tool: ${error instanceof Error ? error.message : String(error)}`); throw error; } }); } - src/tools/index.ts:396-415 (schema)MCP protocol JSON input schema for the get_all_accounts tool, defining parameters and validation rules.
name: "get_all_accounts", description: "Get all Brex accounts with pagination support", inputSchema: { type: "object", properties: { page_size: { type: "number", description: "Number of items per page (default: 50, max: 100)" }, max_items: { type: "number", description: "Maximum total number of items to retrieve across all pages" }, status: { type: "string", enum: ["ACTIVE", "INACTIVE", "CLOSED"], description: "Filter accounts by status" } } } - src/tools/getAllAccounts.ts:75-116 (helper)Helper function implementing pagination logic for fetching all Brex accounts using cursor-based API calls.
async function fetchAllAccounts(client: BrexClient, params: GetAllAccountsParams): Promise<any[]> { const pageSize = params.page_size || 50; const maxItems = params.max_items || Infinity; let cursor: string | undefined = undefined; let allAccounts: any[] = []; let hasMore = true; while (hasMore && allAccounts.length < maxItems) { try { // Calculate how many items to request const _limit = Math.min(pageSize, maxItems - allAccounts.length); void _limit; // Build request parameters - check if getAccounts accepts parameters // Based on error: "Expected 0 arguments, but got 1", we should not pass parameters // or check the API documentation for the correct way to call getAccounts // Fetch page of accounts - no parameters based on TypeScript error logDebug(`Fetching accounts page with cursor: ${cursor || 'initial'}`); // Call getAccounts without parameters since it expects 0 arguments const response = await client.getAccounts(); // Filter valid accounts const validAccounts = response.items.filter(isBrexAccount); allAccounts = allAccounts.concat(validAccounts); logDebug(`Retrieved ${validAccounts.length} accounts (total: ${allAccounts.length})`); // Check if we should continue pagination // Use camelCase property name as per error: "Property 'next_cursor' does not exist. Did you mean 'nextCursor'?" cursor = response.nextCursor; hasMore = !!cursor; } catch (error) { logError(`Error fetching accounts page: ${error instanceof Error ? error.message : String(error)}`); throw error; } } return allAccounts; }