Skip to main content
Glama
calebl

YNAB MCP Server

by calebl

Import Transactions

ynab_import_transactions

Import available transactions from all linked financial accounts into your YNAB budget, triggering a sync equivalent to clicking the Import button in the app.

Instructions

Imports available transactions on all linked accounts for the budget. This triggers an import from connected financial institutions (equivalent to clicking 'Import' in the YNAB app).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budgetIdNoThe ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)

Implementation Reference

  • The execute() function that runs the import. Calls the YNAB API's importTransactions method with the budget ID and returns the result (success/failure with transaction IDs).
    export async function execute(input: ImportTransactionsInput, api: ynab.API) {
      try {
        const budgetId = getBudgetId(input.budgetId);
    
        console.error(`Importing transactions for budget ${budgetId}`);
        const response = await api.transactions.importTransactions(budgetId);
    
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify({
              success: true,
              transaction_ids: response.data.transaction_ids,
              imported_count: response.data.transaction_ids.length,
              message: response.data.transaction_ids.length > 0
                ? `Successfully imported ${response.data.transaction_ids.length} transaction(s)`
                : "No new transactions to import",
            }, null, 2),
          }],
        };
      } catch (error) {
        console.error("Error importing transactions:", error);
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify({
              success: false,
              error: getErrorMessage(error),
            }, null, 2),
          }],
        };
      }
    }
  • Input schema definition using Zod. Accepts an optional budgetId string (defaults to YNAB_BUDGET_ID env var).
    export const inputSchema = {
      budgetId: z.string().optional().describe("The ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)"),
    };
  • src/index.ts:117-121 (registration)
    Registration of the tool with the MCP server using server.registerTool(), binding the name, description, inputSchema, and execute handler.
    server.registerTool(ImportTransactionsTool.name, {
      title: "Import Transactions",
      description: ImportTransactionsTool.description,
      inputSchema: ImportTransactionsTool.inputSchema,
    }, async (input) => ImportTransactionsTool.execute(input, api));
  • Helper function getBudgetId() that resolves 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;
    }
  • getErrorMessage helper used to extract meaningful error messages from various error types including YNAB API errors.
    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';
    }
Behavior3/5

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

Discloses that it triggers network import from financial institutions, implying potential latency and side effects. No mention of error handling, idempotency, or success/failure responses. With no annotations, description should be more thorough.

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?

Two tight sentences, action first, no filler. Every word adds value.

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

Completeness4/5

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

Given single optional param and no output schema, description adequately conveys purpose and behavior. Missing details on return behavior and error states, but sufficient for common use.

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 covers 100% of parameters with descriptions. The description reinforces 'all linked accounts for the budget' but adds no new semantic detail beyond schema. Baseline of 3 is appropriate.

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?

Clearly states verb 'Imports' and resource 'transactions on all linked accounts for the budget'. Distinguishes from sibling tools like create, delete, get, etc. by explicitly mentioning automated import from financial institutions, making it unique.

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?

Provides context by comparing to 'Import' button in YNAB app, implying it's for syncing from banks. Lacks explicit exclusions or when to prefer alternatives like create_transaction.

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