get_expense
Retrieve an expense by ID to access full details, receipts, and billing information.
Instructions
Retrieve a specific expense by ID with complete details including receipts and billing information.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expense_id | Yes | The ID of the expense to retrieve |
Implementation Reference
- src/tools/expenses.ts:39-57 (handler)The GetExpenseHandler class that implements the 'get_expense' tool logic. It validates input (expects expense_id), fetches the expense from the Harvest API, and returns the result.
class GetExpenseHandler implements ToolHandler { constructor(private readonly config: BaseToolConfig) {} async execute(args: Record<string, any>): Promise<CallToolResult> { try { const inputSchema = z.object({ expense_id: z.number().int().positive() }); const { expense_id } = validateInput(inputSchema, args, 'get expense'); logger.info('Fetching expense from Harvest API', { expenseId: expense_id }); const expense = await this.config.harvestClient.getExpense(expense_id); return { content: [{ type: 'text', text: JSON.stringify(expense, null, 2) }], }; } catch (error) { return handleMCPToolError(error, 'get_expense'); } } } - src/tools/expenses.ts:158-172 (registration)Registration of the 'get_expense' tool with its name, description, input schema (expense_id required), and handler binding (new GetExpenseHandler(config)).
{ tool: { name: 'get_expense', description: 'Retrieve a specific expense by ID with complete details including receipts and billing information.', inputSchema: { type: 'object', properties: { expense_id: { type: 'number', description: 'The ID of the expense to retrieve' }, }, required: ['expense_id'], additionalProperties: false, }, }, handler: new GetExpenseHandler(config), }, - src/tools/expenses.ts:44-44 (schema)Inline input schema for get_expense using zod: expects expense_id as a positive integer.
const inputSchema = z.object({ expense_id: z.number().int().positive() }); - src/client/expenses-client.ts:45-61 (helper)The ExpensesClient.getExpense() API client method that makes the actual HTTP GET request to /expenses/{expenseId}.
async getExpense(expenseId: number): Promise<any> { try { this.logger.debug('Fetching expense', { expenseId }); const response: AxiosResponse = await this.client.get(`/expenses/${expenseId}`); this.logger.info('Successfully retrieved expense', { expenseId: response.data.id, totalCost: response.data.total_cost, spentDate: response.data.spent_date }); return response.data; } catch (error) { this.logger.error('Failed to retrieve expense', { expenseId, error: (error as Error).message }); throw error; } } - src/server.ts:139-139 (registration)The 'get_expense' tool name is listed under the 'expenses' category mapping in the server, enabling tool filtering by category.
'expenses': ['list_expenses', 'get_expense', 'create_expense', 'update_expense', 'delete_expense', 'list_expense_categories'],