Skip to main content
Glama
crazyrabbitLTC

Brex MCP Server

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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'pagination support,' which is useful context beyond the input schema, but fails to describe critical behaviors like rate limits, authentication needs, error handling, or what the return format looks like (e.g., list structure, metadata). For a read operation with pagination, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Get all Brex accounts') and adds a key behavioral trait ('with pagination support'). There is no wasted verbiage, and every word earns its place, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (pagination, filtering), lack of annotations, and no output schema, the description is minimally adequate but incomplete. It covers the basic purpose and hints at pagination but misses details on return values, error cases, and usage context. It's sufficient for a simple read tool but could be more comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, providing clear details for all three parameters (page_size, max_items, status). The description adds no additional parameter semantics beyond what's in the schema, such as default behaviors or interaction effects. According to the rules, with high schema coverage (>80%), the baseline is 3 even without param info in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('all Brex accounts'), making the purpose unambiguous. It distinguishes from sibling tools like 'get_account_details' by specifying it retrieves all accounts rather than details of a specific one. However, it doesn't explicitly differentiate from other list tools like 'get_all_expenses' beyond the resource name.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer 'get_all_accounts' over 'get_account_details' or other sibling tools, nor does it specify prerequisites or exclusions. The mention of 'pagination support' hints at usage for large datasets but isn't explicit guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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