Skip to main content
Glama
crazyrabbitLTC

Brex MCP Server

get_expense

Retrieve detailed expense information from Brex by providing a specific expense ID, returning the complete expense object with optional merchant details.

Instructions

Get a single expense by ID. Returns the complete expense object. Example: {"expense_id":"expense_123","expand":["merchant"]}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expense_idYesExpense ID
expandNo

Implementation Reference

  • Core execution logic for the get_expense tool: parameter validation, Brex API call to retrieve single expense by ID with optional expand fields, returns JSON-formatted response.
    registerToolHandler("get_expense", async (request: ToolCallRequest) => {
      try {
        const params = validateParams(request.params.arguments);
        const client = getBrexClient();
        const expense = await client.getExpense(params.expense_id, { expand: params.expand });
        return {
          content: [{
            type: "text",
            text: JSON.stringify(expense, null, 2)
          }]
        };
      } catch (error) {
        logError(`Error in get_expense: ${error instanceof Error ? error.message : String(error)}`);
        throw error;
      }
    });
  • TypeScript interface and validation function defining the input schema for get_expense: requires expense_id (string), optional expand (string array).
    interface GetExpenseParams {
      expense_id: string;
      expand?: string[];
    }
    
    function validateParams(input: unknown): GetExpenseParams {
      const raw = (input || {}) as Record<string, unknown>;
      if (!raw.expense_id) throw new Error("Missing required parameter: expense_id");
      const out: GetExpenseParams = { expense_id: String(raw.expense_id) };
      if (raw.expand !== undefined) out.expand = Array.isArray(raw.expand) ? raw.expand.map(String) : [String(raw.expand)];
      return out;
    }
  • Registers the get_expense tool handler by calling registerToolHandler with the name and async handler function.
    export function registerGetExpenseById(_server: Server): void {
      registerToolHandler("get_expense", async (request: ToolCallRequest) => {
        try {
          const params = validateParams(request.params.arguments);
          const client = getBrexClient();
          const expense = await client.getExpense(params.expense_id, { expand: params.expand });
          return {
            content: [{
              type: "text",
              text: JSON.stringify(expense, null, 2)
            }]
          };
        } catch (error) {
          logError(`Error in get_expense: ${error instanceof Error ? error.message : String(error)}`);
          throw error;
        }
      });
    }
  • JSON Schema definition for the get_expense tool input, used in the MCP list_tools response to describe parameters to the LLM.
    name: "get_expense",
    description: "Get a single expense by ID. Returns the complete expense object. Example: {\"expense_id\":\"expense_123\",\"expand\":[\"merchant\"]}",
    inputSchema: {
      type: "object",
      properties: {
        expense_id: { type: "string", description: "Expense ID" },
        expand: { type: "array", items: { type: "string" } }
      },
      required: ["expense_id"]
    }
  • Invokes the registerGetExpenseById function to add the get_expense tool during server tool registration in registerTools.
    registerGetExpenseById(server);

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