Skip to main content
Glama
calebl

YNAB MCP Server

by calebl

Approve Transaction

ynab_approve_transaction

Approve or unapprove a specific transaction in your YNAB budget to manage your financial records and maintain accurate budget tracking.

Instructions

Approves an existing transaction in your YNAB budget.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budgetIdNoThe id of the budget containing the transaction (optional, defaults to the budget set in the YNAB_BUDGET_ID environment variable)
transactionIdYesThe id of the transaction to approve
approvedNoWhether the transaction should be marked as approved

Implementation Reference

  • The main handler function that executes the tool logic: fetches the transaction, updates its approved status using YNAB API, handles errors, and returns formatted JSON response.
    export async function execute(input: ApproveTransactionInput, api: ynab.API) {
      try {
        const budgetId = getBudgetId(input.budgetId);
    
        // First, get the existing transaction to ensure we don't lose any data
        const existingTransaction = await api.transactions.getTransactionById(budgetId, input.transactionId);
    
        if (!existingTransaction.data.transaction) {
          throw new Error("Transaction not found");
        }
    
        const existingTransactionData = existingTransaction.data.transaction;
    
        const transaction: ynab.PutTransactionWrapper = {
          transaction: {
            approved: input.approved ?? true,
          }
        };
    
        const response = await api.transactions.updateTransaction(
          budgetId,
          existingTransactionData.id,
          transaction
        );
    
        if (!response.data.transaction) {
          throw new Error("Failed to update transaction - no transaction data returned");
        }
    
        return {
          content: [{ type: "text" as const, text: JSON.stringify({
            success: true,
            transactionId: response.data.transaction.id,
            message: "Transaction updated successfully",
          }, null, 2) }]
        };
      } catch (error) {
        console.error("Error approving transaction:", error);
        return {
          content: [{ type: "text" as const, text: JSON.stringify({
            success: false,
            error: getErrorMessage(error),
          }, null, 2) }]
        };
      }
    }
  • src/index.ts:57-61 (registration)
    Registers the 'ynab_approve_transaction' tool with the MCP server, specifying title, description, input schema, and handler.
    server.registerTool(ApproveTransactionTool.name, {
      title: "Approve Transaction",
      description: ApproveTransactionTool.description,
      inputSchema: ApproveTransactionTool.inputSchema,
    }, async (input) => ApproveTransactionTool.execute(input, api));
  • Zod-based input schema defining parameters for budgetId, transactionId, and approved flag.
    export const inputSchema = {
      budgetId: z.string().optional().describe("The id of the budget containing the transaction (optional, defaults to the budget set in the YNAB_BUDGET_ID environment variable)"),
      transactionId: z.string().describe("The id of the transaction to approve"),
      approved: z.boolean().optional().default(true).describe("Whether the transaction should be marked as approved"),
    };
  • Helper function to resolve budget ID from input or environment variable, with validation.
    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;
    }
  • Shared utility function to extract meaningful error messages from errors, including YNAB API responses, used in the handler.
    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 provided, the description carries the full burden of behavioral disclosure. It states the tool 'approves' a transaction, implying a mutation, but doesn't describe what happens upon approval (e.g., affects budget calculations, requires permissions), potential side effects, or error conditions. This is a significant gap for a mutation tool with zero annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with every part earning its place.

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

Completeness2/5

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

Given this is a mutation tool with no annotations, no output schema, and 3 parameters, the description is incomplete. It lacks behavioral context (e.g., what approval entails, error handling), usage guidance, and doesn't address the 'approved' parameter's default behavior, leaving gaps for an AI agent to correctly invoke it.

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?

The description adds no parameter semantics beyond what the input schema provides. Since schema description coverage is 100%, the schema already documents all three parameters thoroughly. The baseline score of 3 is appropriate as the description doesn't compensate but the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('approves') and resource ('an existing transaction in your YNAB budget'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'ynab_bulk_approve_transactions' or 'ynab_update_transaction', which could also modify transaction approval status.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., transaction must exist, be unapproved), nor does it clarify when to choose this over 'ynab_bulk_approve_transactions' for multiple transactions or 'ynab_update_transaction' for other modifications.

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