get_expense
Retrieve detailed expense information from Brex financial platform by providing a specific expense ID to access complete expense data and related 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
| Name | Required | Description | Default |
|---|---|---|---|
| expand | No | ||
| expense_id | Yes | Expense ID |
Implementation Reference
- src/tools/getExpenseById.ts:28-43 (handler)The core handler function for the 'get_expense' tool. Validates input parameters, fetches the specific expense using BrexClient.getExpense, formats it as JSON, and returns it as text content.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; } });
- src/tools/index.ts:160-167 (schema)JSON input schema for the 'get_expense' tool, defining required 'expense_id' and optional 'expand' array, used in the listTools response.inputSchema: { type: "object", properties: { expense_id: { type: "string", description: "Expense ID" }, expand: { type: "array", items: { type: "string" } } }, required: ["expense_id"] }
- src/tools/index.ts:58-58 (registration)Registration call for the 'get_expense' tool handler during server setup in registerTools function.registerGetExpenseById(server);
- src/tools/getExpenseById.ts:27-44 (registration)The registration function exported from getExpenseById.ts, which registers the tool handler with name 'get_expense' using registerToolHandler.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; } }); }
- src/tools/getExpenseById.ts:14-25 (schema)TypeScript interface and validation function for input parameters of 'get_expense' tool.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; }