get_all_categories
Retrieve a comprehensive list of all financial categories from your LunchMoney account, available in flattened alphabetical order or nested hierarchical format for better organization.
Instructions
Get a flattened list of all categories in alphabetical order associated with the user's account.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes |
Implementation Reference
- src/tools/categories.ts:20-50 (handler)The handler function for the get_all_categories tool. It fetches categories from the Lunchmoney API endpoint `/categories` with optional format parameter, handles errors, and returns JSON stringified categories.async ({ input }) => { const format = input.format || "flattened"; const { baseUrl, lunchmoneyApiToken } = getConfig(); const response = await fetch(`${baseUrl}/categories?format=${format}`, { headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to get all categories: ${response.statusText}`, }, ], }; } const categories: Category[] = await response.json(); return { content: [ { type: "text", text: JSON.stringify(categories), }, ], }; }
- src/tools/categories.ts:11-18 (schema)The input schema for the get_all_categories tool, defining an optional 'format' parameter using Zod.input: z.object({ format: z .string() .optional() .describe( "Can either flattened or nested. If flattened, returns a singular array of categories, ordered alphabetically. If nested, returns top-level categories (either category groups or categories not part of a category group) in an array. Subcategories are nested within the category group under the property children." ), }),
- src/tools/categories.ts:7-51 (registration)The registration of the get_all_categories tool within the registerCategoryTools function using server.tool().server.tool( "get_all_categories", "Get a flattened list of all categories in alphabetical order associated with the user's account.", { input: z.object({ format: z .string() .optional() .describe( "Can either flattened or nested. If flattened, returns a singular array of categories, ordered alphabetically. If nested, returns top-level categories (either category groups or categories not part of a category group) in an array. Subcategories are nested within the category group under the property children." ), }), }, async ({ input }) => { const format = input.format || "flattened"; const { baseUrl, lunchmoneyApiToken } = getConfig(); const response = await fetch(`${baseUrl}/categories?format=${format}`, { headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to get all categories: ${response.statusText}`, }, ], }; } const categories: Category[] = await response.json(); return { content: [ { type: "text", text: JSON.stringify(categories), }, ], }; } );