Skip to main content
Glama
dgalarza

YNAB MCP Server

by dgalarza

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
NameRequiredDescriptionDefault
budget_idYes

Implementation Reference

  • 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)
  • 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
  • The @mcp.tool() decorator registers the get_accounts function as an MCP tool.
    @mcp.tool()

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/dgalarza/ynab-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server