Skip to main content
Glama
calebl

YNAB MCP Server

by calebl

Create Transaction

ynab_create_transaction

Create a new transaction in YNAB by supplying account, date, and amount. Optionally set payee, category, memo, cleared, approved, or flag color.

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

  • The main execution function for the ynab_create_transaction tool. Converts dollar amounts to milliunits, builds a PostTransactionsWrapper, calls the YNAB API's createTransaction endpoint, and returns success/error responses.
    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) }]
        };
      }
    }
  • Input schema definition using Zod, describing all optional and required parameters (budgetId, accountId, date, amount, payeeId, payeeName, categoryId, memo, cleared, approved, flagColor).
    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)"),
    };
  • TypeScript interface defining the shape of the CreateTransactionInput object used by the execute function.
    interface CreateTransactionInput {
      budgetId?: string;
      accountId: string;
      date: string;
      amount: number;
      payeeId?: string;
      payeeName?: string;
      categoryId?: string;
      memo?: string;
      cleared?: boolean;
      approved?: boolean;
      flagColor?: string;
    }
  • src/index.ts:51-55 (registration)
    Registration of the tool with the MCP server using server.registerTool(), linking the name 'ynab_create_transaction' to the inputSchema and execute handler.
    server.registerTool(CreateTransactionTool.name, {
      title: "Create Transaction",
      description: CreateTransactionTool.description,
      inputSchema: CreateTransactionTool.inputSchema,
    }, async (input) => CreateTransactionTool.execute(input, api));
  • Helper function getErrorMessage used to extract meaningful error messages from various error types including YNAB API error responses.
    export function getErrorMessage(error) {
        // 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.error === 'object') {
            const ynabError = error.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?

No annotations provided, so description carries full burden. Fails to mention side effects (budget balance changes), idempotency, rate limits, or error conditions. Minimal disclosure.

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?

Single sentence, no redundancy, conveys essential function and a key constraint efficiently.

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?

No output schema, description omits response details. For 11 parameters, lacks guidance on default behavior for optional fields or error handling. Incomplete for a creation tool.

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

Parameters4/5

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

Schema coverage is 100% with good descriptions. Description adds value by clarifying mutual exclusivity of payeeId/payeeName, which is not evident from schema. Baseline 3 + 1 for this insight.

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?

Description clearly states verb 'creates' with resource 'new transaction in YNAB budget'. Distinct from siblings like get, delete, import. Constraint on payee fields adds specificity.

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?

No guidance on when to use this vs alternatives (e.g., import, update). Does not mention prerequisites or context for creation. Only mentions a constraint but no usage context.

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