Skip to main content
Glama
calebl

YNAB MCP Server

by calebl

Get Unapproved Transactions

ynab_get_unapproved_transactions

Retrieve unapproved transactions from a YNAB budget. Initial fetch covers the past 3 days; subsequent calls return only new or changed transactions since the last query.

Instructions

Gets unapproved transactions from a budget. First time pulls last 3 days, subsequent pulls use server knowledge to get only changes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budgetIdNoThe ID of the budget to fetch transactions for (optional, defaults to the budget set in the YNAB_BUDGET_ID environment variable)

Implementation Reference

  • The execute function that fetches unapproved transactions from the YNAB API and returns them formatted.
    export async function execute(input: GetUnapprovedTransactionsInput, api: ynab.API) {
      try {
        const budgetId = getBudgetId(input.budgetId);
    
        console.error(`Getting unapproved transactions for budget ${budgetId}`);
    
        const response = await api.transactions.getTransactions(
          budgetId,
          undefined,
          ynab.GetTransactionsTypeEnum.Unapproved
        );
    
        // Transform the transactions to a more readable format
        const transactions = response.data.transactions
          .filter((transaction) => !transaction.deleted)
          .map((transaction) => ({
            id: transaction.id,
            date: transaction.date,
            amount: (transaction.amount / 1000).toFixed(2), // Convert milliunits to actual currency
            memo: transaction.memo,
            approved: transaction.approved,
            account_name: transaction.account_name,
            payee_name: transaction.payee_name,
            category_name: transaction.category_name,
            transfer_account_id: transaction.transfer_account_id,
            transfer_transaction_id: transaction.transfer_transaction_id,
            matched_transaction_id: transaction.matched_transaction_id,
            import_id: transaction.import_id,
          }));
    
        return {
          content: [{ type: "text" as const, text: JSON.stringify({
            transactions,
            transaction_count: transactions.length,
          }, null, 2) }]
        };
      } catch (error) {
        console.error("Error getting unapproved transactions:", error);
        return {
          content: [{ type: "text" as const, text: JSON.stringify({
            success: false,
            error: getErrorMessage(error),
          }, null, 2) }]
        };
      }
    }
  • Input schema using zod - defines optional budgetId parameter.
    export const inputSchema = {
      budgetId: z.string().optional().describe("The ID of the budget to fetch transactions for (optional, defaults to the budget set in the YNAB_BUDGET_ID environment variable)"),
    };
  • src/index.ts:39-43 (registration)
    Registration of the tool with the MCP server, binding name, description, inputSchema, and execute handler.
    server.registerTool(GetUnapprovedTransactionsTool.name, {
      title: "Get Unapproved Transactions",
      description: GetUnapprovedTransactionsTool.description,
      inputSchema: GetUnapprovedTransactionsTool.inputSchema,
    }, async (input) => GetUnapprovedTransactionsTool.execute(input, api));
  • Helper function that resolves the budget ID from input param or env var, with error handling.
    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;
    }
  • Utility used by the execute function to extract 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?

With no annotations, the description carries the full burden. It discloses key behavioral traits: first call fetches last 3 days, subsequent calls use server knowledge for incremental updates. This is helpful, but it omits other traits like read-only nature, authorization requirements, or rate limits. The provided information is decent but not comprehensive.

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 two sentences with no wasted words. It front-loads the core action and efficiently adds operational detail. Every sentence earns 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?

The description fails to mention output format, pagination, or any return structure. There is no output schema, so the description must compensate. For a simple fetch tool, the absence of output details makes it incomplete for an agent to fully understand what the tool returns.

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 input schema has 100% coverage for the single optional parameter, with a clear description of its default behavior. The description does not add any additional meaning beyond what the schema already provides. Thus baseline 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?

The description clearly states the action ('gets'), the resource ('unapproved transactions'), and the context ('from a budget'). It distinguishes from sibling tools like 'ynab_get_transactions' by specifying 'unapproved'. The addition of first-time vs. subsequent behavior further clarifies its scope.

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 implies usage for unapproved transactions via the first sentence, but it does not explicitly state when to use this tool versus alternatives like 'ynab_get_transactions'. It gives operational guidance on first-time vs. subsequent calls but lacks explicit 'when-not-to-use' or comparison to siblings.

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