add_to_category_group
Organize financial categories by adding existing categories or creating new ones within a specified category group to improve budget management.
Instructions
Add categories (either existing or new) to a single category group.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes |
Implementation Reference
- src/tools/categories.ts:450-494 (handler)The handler function for the 'add_to_category_group' tool. It constructs a request body from category_ids and/or new_categories, then performs a POST request to the LunchMoney API endpoint `/categories/group/${group_id}/add` to add categories to the specified group, returning the JSON response or an error message.async ({ input }) => { const { group_id, category_ids, new_categories } = input; const { baseUrl, lunchmoneyApiToken } = getConfig(); const requestBody: any = {}; if (category_ids && category_ids.length > 0) { requestBody.category_ids = category_ids; } if (new_categories && new_categories.length > 0) { requestBody.new_categories = new_categories; } const response = await fetch( `${baseUrl}/categories/group/${group_id}/add`, { method: "POST", headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, "Content-Type": "application/json", }, body: JSON.stringify(requestBody), } ); if (!response.ok) { return { content: [ { type: "text", text: `Failed to add to a single category group: ${response.statusText}`, }, ], }; } return { content: [ { type: "text", text: JSON.stringify(await response.json()), }, ], }; }
- src/tools/categories.ts:434-448 (schema)Zod input schema defining parameters for the 'add_to_category_group' tool: group_id (required number), optional category_ids (array of numbers), and optional new_categories (array of strings).input: z.object({ group_id: z.number().describe("Id of the parent group to add to."), category_ids: z .array(z.number()) .optional() .describe( "Array of category_id to include in the category group." ), new_categories: z .array(z.string()) .optional() .describe( "Array of strings representing new categories to create and subsequently include in the category group." ), }),
- src/tools/categories.ts:430-495 (registration)The server.tool() registration call that defines and registers the 'add_to_category_group' tool, including its name, description, input schema, and handler function within the registerCategoryTools function.server.tool( "add_to_category_group", "Add categories (either existing or new) to a single category group.", { input: z.object({ group_id: z.number().describe("Id of the parent group to add to."), category_ids: z .array(z.number()) .optional() .describe( "Array of category_id to include in the category group." ), new_categories: z .array(z.string()) .optional() .describe( "Array of strings representing new categories to create and subsequently include in the category group." ), }), }, async ({ input }) => { const { group_id, category_ids, new_categories } = input; const { baseUrl, lunchmoneyApiToken } = getConfig(); const requestBody: any = {}; if (category_ids && category_ids.length > 0) { requestBody.category_ids = category_ids; } if (new_categories && new_categories.length > 0) { requestBody.new_categories = new_categories; } const response = await fetch( `${baseUrl}/categories/group/${group_id}/add`, { method: "POST", headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, "Content-Type": "application/json", }, body: JSON.stringify(requestBody), } ); if (!response.ok) { return { content: [ { type: "text", text: `Failed to add to a single category group: ${response.statusText}`, }, ], }; } return { content: [ { type: "text", text: JSON.stringify(await response.json()), }, ], }; } );