Skip to main content
Glama

get_all_accounts

Retrieve all Brex accounts with pagination support, allowing filtering by status and control over the number of items returned per page.

Instructions

Get all Brex accounts with pagination support

Input Schema

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

Implementation Reference

  • Core execution logic for the get_all_accounts tool: validates params, fetches paginated accounts from Brex API, filters valid accounts, and formats response as JSON.
    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 input schema definition for the get_all_accounts tool, registered in the listTools handler.
    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" } } } },
  • Registers the get_all_accounts handler function with the toolHandlers map.
    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; } }); }
  • Top-level registration call during server setup in registerTools function.
    registerGetAllAccounts(server);
  • Helper function implementing pagination to fetch all accounts from Brex API.
    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; }
  • Validates input parameters for the tool against expected types and ranges.
    function validateParams(input: any): GetAllAccountsParams { if (!input) { return {}; // All parameters are optional } const params: GetAllAccountsParams = {}; // Validate page_size if provided if (input.page_size !== undefined) { const pageSize = parseInt(input.page_size.toString(), 10); if (isNaN(pageSize) || pageSize <= 0 || pageSize > 100) { throw new Error("Invalid page_size: must be a positive number between 1 and 100"); } params.page_size = pageSize; } // Validate max_items if provided if (input.max_items !== undefined) { const maxItems = parseInt(input.max_items.toString(), 10); if (isNaN(maxItems) || maxItems <= 0) { throw new Error("Invalid max_items: must be a positive number"); } params.max_items = maxItems; } // Validate status if provided if (input.status !== undefined) { const validStatuses = ['ACTIVE', 'INACTIVE', 'CLOSED']; if (!validStatuses.includes(input.status.toUpperCase())) { throw new Error(`Invalid status: must be one of ${validStatuses.join(', ')}`); } params.status = input.status.toUpperCase(); } return params; }
  • TypeScript interface defining the input parameters for the tool.
    interface GetAllAccountsParams { page_size?: number; max_items?: number; status?: string; }

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