Skip to main content
Glama
calebl

YNAB MCP Server

by calebl

Create Transaction

ynab_create_transaction

Add a new transaction to your YNAB budget by specifying account, date, amount, and payee information to track spending and income.

Instructions

Creates a new transaction in your YNAB budget. Either payeeId or payeeName must be provided in addition to the other required fields.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budgetIdNoThe id of the budget to create the transaction in (optional, defaults to the budget set in the YNAB_BUDGET_ID environment variable)
accountIdYesThe id of the account to create the transaction in
dateYesThe date of the transaction in ISO format (e.g. 2024-03-24)
amountYesThe amount in dollars (e.g. 10.99)
payeeIdNoThe id of the payee (optional if payeeName is provided)
payeeNameNoThe name of the payee (optional if payeeId is provided)
categoryIdNoThe category id for the transaction (optional)
memoNoA memo/note for the transaction (optional)
clearedNoWhether the transaction is cleared (optional, defaults to false)
approvedNoWhether the transaction is approved (optional, defaults to false)
flagColorNoThe transaction flag color (red, orange, yellow, green, blue, purple) (optional)

Implementation Reference

  • Main handler function that executes the YNAB transaction creation logic using the YNAB API.
    export async function execute(input: CreateTransactionInput, api: ynab.API) {
      try {
        const budgetId = getBudgetId(input.budgetId);
    
        if(!input.payeeId && !input.payeeName) {
          throw new Error("Either payeeId or payeeName must be provided");
        }
    
        const milliunitAmount = Math.round(input.amount * 1000);
    
        const transaction: ynab.PostTransactionsWrapper = {
          transaction: {
            account_id: input.accountId,
            date: input.date,
            amount: milliunitAmount,
            payee_id: input.payeeId,
            payee_name: input.payeeName,
            category_id: input.categoryId,
            memo: input.memo,
            cleared: input.cleared ? ynab.TransactionClearedStatus.Cleared : ynab.TransactionClearedStatus.Uncleared,
            approved: input.approved ?? false,
            flag_color: input.flagColor as ynab.TransactionFlagColor,
          }
        };
    
        const response = await api.transactions.createTransaction(
          budgetId,
          transaction
        );
    
        if (!response.data.transaction) {
          throw new Error("Failed to create transaction - no transaction data returned");
        }
    
        return {
          content: [{ type: "text" as const, text: JSON.stringify({
            success: true,
            transactionId: response.data.transaction.id,
            message: "Transaction created successfully",
          }, null, 2) }]
        };
      } catch (error) {
        console.error("Error creating transaction:", error);
        return {
          content: [{ type: "text" as const, text: JSON.stringify({
            success: false,
            error: getErrorMessage(error),
          }, null, 2) }]
        };
      }
    }
  • Tool name, description, and input schema definition using Zod.
    export const name = "ynab_create_transaction";
    export const description = "Creates a new transaction in your YNAB budget. Either payeeId or payeeName must be provided in addition to the other required fields.";
    export const inputSchema = {
      budgetId: z.string().optional().describe("The id of the budget to create the transaction in (optional, defaults to the budget set in the YNAB_BUDGET_ID environment variable)"),
      accountId: z.string().describe("The id of the account to create the transaction in"),
      date: z.string().describe("The date of the transaction in ISO format (e.g. 2024-03-24)"),
      amount: z.number().describe("The amount in dollars (e.g. 10.99)"),
      payeeId: z.string().optional().describe("The id of the payee (optional if payeeName is provided)"),
      payeeName: z.string().optional().describe("The name of the payee (optional if payeeId is provided)"),
      categoryId: z.string().optional().describe("The category id for the transaction (optional)"),
      memo: z.string().optional().describe("A memo/note for the transaction (optional)"),
      cleared: z.boolean().optional().describe("Whether the transaction is cleared (optional, defaults to false)"),
      approved: z.boolean().optional().describe("Whether the transaction is approved (optional, defaults to false)"),
      flagColor: z.string().optional().describe("The transaction flag color (red, orange, yellow, green, blue, purple) (optional)"),
    };
  • src/index.ts:51-55 (registration)
    Registers the ynab_create_transaction tool with the MCP server, providing the handler wrapper.
    server.registerTool(CreateTransactionTool.name, {
      title: "Create Transaction",
      description: CreateTransactionTool.description,
      inputSchema: CreateTransactionTool.inputSchema,
    }, async (input) => CreateTransactionTool.execute(input, api));
  • Helper function to retrieve or default the budget ID from input or 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;
    }
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 creates a transaction, implying a write operation, but doesn't mention permissions needed, whether it's idempotent, error handling, or what happens on success (e.g., returns a transaction ID). For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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 extremely concise—two sentences with zero waste. It front-loads the core purpose and follows with a critical parameter constraint, making it easy to parse quickly. Every sentence earns its place by providing essential information.

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 the complexity (11 parameters, mutation tool) and lack of annotations and output schema, the description is incomplete. It doesn't cover behavioral aspects like permissions, side effects, or return values, which are crucial for safe and effective use. The description should do more to compensate for these gaps.

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 schema description coverage is 100%, so the schema already documents all 11 parameters thoroughly. The description adds minimal value by emphasizing the payeeId/payeeName requirement, but doesn't provide additional context beyond what's in the schema (e.g., explaining relationships between parameters). Baseline 3 is appropriate when 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 ('Creates a new transaction') and resource ('in your YNAB budget'), making the purpose unambiguous. However, it doesn't differentiate from sibling tools like 'ynab_import_transactions' or 'ynab_update_transaction', which also involve transaction creation/modification, so it doesn't achieve full sibling differentiation.

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

Usage Guidelines3/5

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

The description provides implied usage guidance by specifying that 'Either payeeId or payeeName must be provided in addition to the other required fields,' which helps understand parameter requirements. However, it doesn't explicitly state when to use this tool versus alternatives like 'ynab_import_transactions' for bulk operations or 'ynab_update_transaction' for modifications, leaving some ambiguity.

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