ynab_list_budgets
Retrieve all available budgets from YNAB to view and manage your financial planning data through the YNAB MCP Server.
Instructions
Lists all available budgets from YNAB API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/ListBudgetsTool.ts:9-38 (handler)The main handler function that executes the tool: fetches and lists YNAB budgets, formats as JSON, handles missing token and errors.export async function execute(_input: Record<string, unknown>, api: ynab.API) { try { if (!process.env.YNAB_API_TOKEN) { return { content: [{ type: "text" as const, text: "YNAB API Token is not set" }] }; } console.error("Listing budgets"); const budgetsResponse = await api.budgets.getBudgets(); console.error(`Found ${budgetsResponse.data.budgets.length} budgets`); const budgets = budgetsResponse.data.budgets.map((budget) => ({ id: budget.id, name: budget.name, })); return { content: [{ type: "text" as const, text: JSON.stringify(budgets, null, 2) }] }; } catch (error: unknown) { console.error("Error listing budgets:", error); return { content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: getErrorMessage(error), }, null, 2) }] }; } }
- src/index.ts:33-37 (registration)Registers the 'ynab_list_budgets' tool with the MCP server, using imported name, description, schema, and execute function.server.registerTool(ListBudgetsTool.name, { title: "List Budgets", description: ListBudgetsTool.description, inputSchema: ListBudgetsTool.inputSchema, }, async (input) => ListBudgetsTool.execute(input, api));
- src/tools/ListBudgetsTool.ts:5-7 (schema)Tool metadata: name, description, and input schema (empty object).export const name = "ynab_list_budgets"; export const description = "Lists all available budgets from YNAB API"; export const inputSchema = {};
- src/tools/ListBudgetsTool.ts:1-3 (helper)Imports for schema validation (zod), YNAB API client, and error handling utility.import { z } from "zod"; import * as ynab from "ynab"; import { getErrorMessage } from "./errorUtils.js";