get_accounts
Retrieve all accounts associated with a specific YNAB budget to view account balances, types, and financial overview for budget management.
Instructions
Get all accounts for a budget.
Args:
budget_id: The ID of the budget (use 'last-used' for default budget)
Returns:
JSON string with list of accounts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| budget_id | Yes |
Implementation Reference
- src/ynab_mcp/server.py:52-64 (handler)MCP tool handler for 'get_accounts'. Decorated with @mcp.tool() for automatic registration and execution. Fetches accounts using YNABClient and serializes to JSON.@mcp.tool() async def get_accounts(budget_id: str) -> str: """Get all accounts for a budget. Args: budget_id: The ID of the budget (use 'last-used' for default budget) Returns: JSON string with list of accounts """ client = get_ynab_client() result = await client.get_accounts(budget_id) return json.dumps(result, indent=2)
- src/ynab_mcp/ynab_client.py:217-249 (helper)Core implementation in YNABClient class. Calls YNAB SDK's get_accounts API, filters out deleted accounts, formats balances from milliunits, returns structured list of accounts.async def get_accounts(self, budget_id: str) -> list[dict[str, Any]]: """Get all accounts for a budget. Args: budget_id: The budget ID or 'last-used' Returns: List of account dictionaries """ try: response = self.client.accounts.get_accounts(budget_id) accounts = [] for account in response.data.accounts: # Skip deleted accounts if account.deleted: continue accounts.append( { "id": account.id, "name": account.name, "type": account.type, "on_budget": account.on_budget, "closed": account.closed, "balance": account.balance / 1000 if account.balance else 0, } ) return accounts except Exception as e: raise Exception(f"Failed to get accounts: {e}") from e
- src/ynab_mcp/server.py:52-52 (registration)The @mcp.tool() decorator registers the get_accounts function as an MCP tool.@mcp.tool()