ynab_get_accounts
Retrieve all accounts in a YNAB budget along with their current balances. Specify a budget ID or use 'last-used' for the most recent budget. Useful for checking account statuses.
Instructions
List all accounts in a budget with their current balances.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/ynab_mcp_server/server.py:115-155 (handler)Main handler for ynab_get_accounts tool. Fetches accounts from YNAB API for a given budget_id, groups them by type (filtering out deleted/closed), formats balances in currency, and returns a markdown summary with total balance.
@mcp.tool( name="ynab_get_accounts", annotations={ "title": "List Accounts", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False, } ) async def ynab_get_accounts(params: GetAccountsInput) -> str: """List all accounts in a budget with their current balances.""" try: async with YNABClient() as client: accounts = await client.get_accounts(params.budget_id) by_type = {} for a in accounts: if a.get("deleted") or a.get("closed"): continue atype = a.get("type", "other") if atype not in by_type: by_type[atype] = [] by_type[atype].append(a) result = "## Accounts\n\n" total_balance = 0 for atype, accts in by_type.items(): result += f"### {atype.replace('_', ' ').title()}\n\n" for a in accts: balance = a.get("balance", 0) total_balance += balance result += f"- **{a['name']}**: {format_currency(balance)}\n" result += f" - ID: `{a['id']}`\n" result += "\n" result += f"**Total Balance: {format_currency(total_balance)}**\n" return result except Exception as e: return format_error(e) - src/ynab_mcp_server/models.py:45-47 (schema)Input schema for ynab_get_accounts. Extends BudgetIdInput which provides a budget_id field (default 'last-used') with whitespace stripping.
class GetAccountsInput(BudgetIdInput): """Input for listing accounts in a budget.""" pass - src/ynab_mcp_server/server.py:115-124 (registration)Registers ynab_get_accounts as an MCP tool via @mcp.tool() decorator with read-only, idempotent annotations.
@mcp.tool( name="ynab_get_accounts", annotations={ "title": "List Accounts", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False, } ) - src/ynab_mcp_server/api.py:212-215 (helper)API client method that calls YNAB's GET /budgets/{budget_id}/accounts endpoint and returns the accounts list.
async def get_accounts(self, budget_id: str) -> List[Dict[str, Any]]: """Get all accounts for a budget.""" response = await self._request("GET", f"/budgets/{budget_id}/accounts") return response["data"]["accounts"] - src/ynab_mcp_server/models.py:17-24 (schema)Base input schema inherited by GetAccountsInput, providing the budget_id field with 'last-used' default.
class BudgetIdInput(BaseModel): """Base model with budget_id field.""" model_config = ConfigDict(str_strip_whitespace=True) budget_id: str = Field( default="last-used", description="Budget ID or 'last-used' for the most recently accessed budget", )