Skip to main content
Glama
akutishevsky

LunchMoney MCP Server

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
NameRequiredDescriptionDefault
inputYes

Implementation Reference

  • 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),
                },
            ],
        };
    }
  • 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)"
            ),
    }),
  • 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),
                    },
                ],
            };
        }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/akutishevsky/lunchmoney-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server