Skip to main content
Glama
calebl

YNAB MCP Server

by calebl

Get Transactions

ynab_get_transactions

Retrieve budget transactions from YNAB with filters for date range, account, category, payee, or approval status to analyze spending patterns.

Instructions

Gets transactions from a budget with optional filters. Can filter by date range, account, category, payee, or approval status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budgetIdNoThe ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)
sinceDateNoOnly return transactions on or after this date (ISO format: 2024-01-01)
typeNoFilter by transaction type. Defaults to 'all'.
accountIdNoFilter to only transactions in this account
categoryIdNoFilter to only transactions in this category
payeeIdNoFilter to only transactions with this payee
limitNoMaximum number of transactions to return (default: 100)

Implementation Reference

  • The main execute function that implements the tool logic: determines budget ID, calls appropriate YNAB API endpoints based on filters (account, category, payee), processes transactions (filter deleted, limit, format amount), and returns JSON response or error.
    export async function execute(input: GetTransactionsInput, api: ynab.API) {
      try {
        const budgetId = getBudgetId(input.budgetId);
        const limit = input.limit || 100;
    
        let rawTransactions: TransactionData[];
    
        // Use the appropriate API method based on filters
        if (input.accountId) {
          const response = await api.transactions.getTransactionsByAccount(
            budgetId,
            input.accountId,
            input.sinceDate,
            mapTransactionType(input.type) as ynab.GetTransactionsByAccountTypeEnum
          );
          rawTransactions = response.data.transactions;
        } else if (input.categoryId) {
          const response = await api.transactions.getTransactionsByCategory(
            budgetId,
            input.categoryId,
            input.sinceDate,
            mapTransactionType(input.type) as ynab.GetTransactionsByCategoryTypeEnum
          );
          rawTransactions = response.data.transactions;
        } else if (input.payeeId) {
          const response = await api.transactions.getTransactionsByPayee(
            budgetId,
            input.payeeId,
            input.sinceDate,
            mapTransactionType(input.type) as ynab.GetTransactionsByPayeeTypeEnum
          );
          rawTransactions = response.data.transactions;
        } else {
          const response = await api.transactions.getTransactions(
            budgetId,
            input.sinceDate,
            mapTransactionType(input.type)
          );
          rawTransactions = response.data.transactions;
        }
    
        // Filter out deleted and apply limit
        const transactions = rawTransactions
          .filter((txn) => !txn.deleted)
          .slice(0, limit)
          .map((txn) => ({
            id: txn.id,
            date: txn.date,
            amount: (txn.amount / 1000).toFixed(2),
            memo: txn.memo,
            approved: txn.approved,
            cleared: txn.cleared,
            account_name: txn.account_name,
            payee_name: txn.payee_name,
            category_name: txn.category_name,
            flag_color: txn.flag_color,
            transfer_account_id: txn.transfer_account_id,
          }));
    
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify({
              transactions,
              transaction_count: transactions.length,
              total_available: rawTransactions.filter((t) => !t.deleted).length,
            }, null, 2),
          }],
        };
      } catch (error) {
        console.error("Error getting transactions:", error);
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify({
              success: false,
              error: getErrorMessage(error),
            }, null, 2),
          }],
        };
      }
    }
  • Zod-based input schema defining optional parameters for budget ID, date filter, transaction type, account/category/payee IDs, and limit.
    export const inputSchema = {
      budgetId: z.string().optional().describe("The ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)"),
      sinceDate: z.string().optional().describe("Only return transactions on or after this date (ISO format: 2024-01-01)"),
      type: z.enum(["all", "uncategorized", "unapproved"]).optional().describe("Filter by transaction type. Defaults to 'all'."),
      accountId: z.string().optional().describe("Filter to only transactions in this account"),
      categoryId: z.string().optional().describe("Filter to only transactions in this category"),
      payeeId: z.string().optional().describe("Filter to only transactions with this payee"),
      limit: z.number().optional().describe("Maximum number of transactions to return (default: 100)"),
    };
  • src/index.ts:87-91 (registration)
    Registers the tool with the MCP server using the exported name, description, schema from GetTransactionsTool, and wraps the execute function with the YNAB API instance.
    server.registerTool(GetTransactionsTool.name, {
      title: "Get Transactions",
      description: GetTransactionsTool.description,
      inputSchema: GetTransactionsTool.inputSchema,
    }, async (input) => GetTransactionsTool.execute(input, api));
  • src/index.ts:16-16 (registration)
    Imports the GetTransactionsTool module to access its exports for registration.
    import * as GetTransactionsTool from "./tools/GetTransactionsTool.js";
  • Helper to get 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 full burden for behavioral disclosure. It states what the tool does but lacks critical behavioral information: it doesn't mention pagination behavior (though 'limit' parameter suggests some), authentication requirements, rate limits, error handling, or what happens when filters return no results. For a read operation with 7 parameters, this leaves significant gaps.

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 perfectly concise with two sentences that directly address core functionality. Every word earns its place - the first sentence states the purpose, the second enumerates filtering options without redundancy. It's front-loaded and wastes no space.

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?

Given 7 parameters with full schema coverage but no annotations and no output schema, the description is minimally adequate. It covers the basic purpose and filtering capabilities but lacks behavioral context that would be crucial for an AI agent to use this tool effectively, especially regarding authentication, error handling, and result format expectations.

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 description coverage is 100%, so the schema already documents all 7 parameters thoroughly. The description adds minimal value beyond the schema by listing filter types ('date range, account, category, payee, or approval status'), but doesn't provide additional context about parameter interactions, precedence, or practical usage examples.

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 verb ('Gets') and resource ('transactions from a budget'), making the purpose immediately understandable. It distinguishes from siblings like 'ynab_get_unapproved_transactions' by mentioning it can filter by multiple criteria including approval status, but doesn't explicitly contrast with that sibling tool.

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 like 'ynab_get_unapproved_transactions' or 'ynab_list_accounts'. It mentions filtering capabilities but doesn't specify use cases, prerequisites, or exclusions for selecting this tool over sibling options.

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