Skip to main content
Glama

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_sizeNoNumber of items per page (default: 50, max: 100)
max_itemsNoMaximum total number of items to retrieve across all pages
statusNoFilter accounts by status

Implementation Reference

  • 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; } });
  • TypeScript interface defining the input parameters for the get_all_accounts tool.
    interface GetAllAccountsParams { page_size?: number; max_items?: number; status?: string; }
  • 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; } }); }
  • 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" } } }
  • 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/crazyrabbitLTC/mcp-brex-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server