Skip to main content
Glama
calebl

YNAB MCP Server

by calebl

Update Category Budget

ynab_update_category_budget

Update a category's budgeted amount for a specific month to allocate funds or move money between categories. This sets the total budgeted amount, not an increment.

Instructions

Updates the budgeted amount for a category in a specific month. Use this to allocate funds to categories or move money between categories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budgetIdNoThe ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)
monthYesThe budget month in ISO format (e.g. 2024-01-01). Must be the first day of the month.
categoryIdYesThe ID of the category to update
budgetedYesThe amount to budget in dollars (e.g. 500.00). This sets the total budgeted amount, not an increment.

Implementation Reference

  • The main `execute` function that performs the YNAB API call to update a category's budget for a specific month. It converts dollars to milliunits, calls `api.categories.updateMonthCategory`, and returns a formatted response.
    export async function execute(input: UpdateCategoryBudgetInput, api: ynab.API) {
      try {
        const budgetId = getBudgetId(input.budgetId);
        const budgetedMilliunits = Math.round(input.budgeted * 1000);
    
        const response = await api.categories.updateMonthCategory(
          budgetId,
          input.month,
          input.categoryId,
          {
            category: {
              budgeted: budgetedMilliunits,
            },
          }
        );
    
        if (!response.data.category) {
          throw new Error("Failed to update category - no category data returned");
        }
    
        const category = response.data.category;
    
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify({
              success: true,
              category: {
                id: category.id,
                name: category.name,
                budgeted: (category.budgeted / 1000).toFixed(2),
                activity: (category.activity / 1000).toFixed(2),
                balance: (category.balance / 1000).toFixed(2),
              },
              message: `Successfully updated ${category.name} budget to $${(category.budgeted / 1000).toFixed(2)}`,
            }, null, 2),
          }],
        };
      } catch (error) {
        console.error("Error updating category budget:", error);
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify({
              success: false,
              error: getErrorMessage(error),
            }, null, 2),
          }],
        };
      }
    }
  • The tool name, description, and Zod-based input schema defining the expected parameters: budgetId (optional), month (ISO date), categoryId, and budgeted (dollar amount).
    export const name = "ynab_update_category_budget";
    export const description = "Updates the budgeted amount for a category in a specific month. Use this to allocate funds to categories or move money between categories.";
    export const inputSchema = {
      budgetId: z.string().optional().describe("The ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)"),
      month: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).describe("The budget month in ISO format (e.g. 2024-01-01). Must be the first day of the month."),
      categoryId: z.string().describe("The ID of the category to update"),
      budgeted: z.number().describe("The amount to budget in dollars (e.g. 500.00). This sets the total budgeted amount, not an increment."),
    };
  • Import of `z` from the zod library used to define the input schema.
    import { z } from "zod";
  • Helper function `getBudgetId` that resolves the budget ID from input or falls back to the YNAB_BUDGET_ID environment variable.
    function getBudgetId(inputBudgetId?: string): string {
      const budgetId = inputBudgetId || process.env.YNAB_BUDGET_ID || "";
      if (!budgetId) {
        throw new Error("No budget ID provided. Please provide a budget ID or set the YNAB_BUDGET_ID environment variable.");
      }
      return budgetId;
    }
  • Utility function `getErrorMessage` used to extract a meaningful error message from various error types including YNAB API error responses.
    export function getErrorMessage(error: unknown): string {
      // Handle standard Error objects
      if (error instanceof Error) {
        return error.message;
      }
    
      // Handle YNAB API error responses which have the structure:
      // { error: { id: '...', name: '...', detail: '...' } }
      if (
        typeof error === 'object' &&
        error !== null &&
        'error' in error &&
        typeof (error as any).error === 'object'
      ) {
        const ynabError = (error as any).error;
        if (ynabError.detail) {
          return ynabError.detail;
        }
        if (ynabError.name) {
          return ynabError.name;
        }
      }
    
      // Fallback: try to stringify the error
      try {
        const stringified = JSON.stringify(error);
        if (stringified !== '{}') {
          return stringified;
        }
      } catch {
        // Ignore stringify errors
      }
    
      return 'Unknown error occurred';
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description should disclose behavioral traits like idempotency, permissions, or side effects. It only states the action and relies on schema for parameter details, missing important context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two sentences, no fluff, and purpose is front-loaded. It could possibly include more structure but is efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the main action and usage but lacks context about optional budgetId defaulting, month format requirements, and absence of output schema. Schema partially compensates but not fully.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds no additional meaning beyond the schema, which already describes each parameter sufficiently.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool updates the budgeted amount for a category in a specific month, and distinguishes from siblings by specifying use for allocation or moving money between categories.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit when to use it (allocate funds or move money between categories), but does not mention when not to use or alternative tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/calebl/ynab-mcp-server'

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