upsert_budget
Create or update monthly budget amounts for specific categories in LunchMoney to manage personal finances and track spending against targets.
Instructions
Create or update a budget for a specific category and month
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes |
Implementation Reference
- src/tools/budgets.ts:90-133 (handler)The handler function for the 'upsert_budget' tool. It constructs a request body with the budget details and sends a PUT request to the Lunch Money API endpoint `/budgets` to create or update the budget. Returns the API response or an error message.async ({ input }) => { const { baseUrl, lunchmoneyApiToken } = getConfig(); const body: any = { start_date: input.start_date, category_id: input.category_id, amount: input.amount, }; if (input.currency) { body.currency = input.currency; } const response = await fetch(`${baseUrl}/budgets`, { method: "PUT", headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to upsert budget: ${response.statusText}`, }, ], }; } const result = await response.json(); return { content: [ { type: "text", text: JSON.stringify(result), }, ], }; }
- src/tools/budgets.ts:76-88 (schema)Zod schema defining the input parameters for the 'upsert_budget' tool: start_date (string), category_id (number), amount (number), and optional currency (string).input: z.object({ start_date: z .string() .describe("Budget month start date in YYYY-MM-DD format"), category_id: z.number().describe("Category ID for the budget"), amount: z.number().describe("Budget amount"), currency: z .string() .optional() .describe( "Currency for budget (defaults to primary currency)" ), }),
- src/tools/budgets.ts:72-134 (registration)Registration of the 'upsert_budget' tool using server.tool(), including name, description, input schema, and handler function.server.tool( "upsert_budget", "Create or update a budget for a specific category and month", { input: z.object({ start_date: z .string() .describe("Budget month start date in YYYY-MM-DD format"), category_id: z.number().describe("Category ID for the budget"), amount: z.number().describe("Budget amount"), currency: z .string() .optional() .describe( "Currency for budget (defaults to primary currency)" ), }), }, async ({ input }) => { const { baseUrl, lunchmoneyApiToken } = getConfig(); const body: any = { start_date: input.start_date, category_id: input.category_id, amount: input.amount, }; if (input.currency) { body.currency = input.currency; } const response = await fetch(`${baseUrl}/budgets`, { method: "PUT", headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to upsert budget: ${response.statusText}`, }, ], }; } const result = await response.json(); return { content: [ { type: "text", text: JSON.stringify(result), }, ], }; } );