Skip to main content
Glama
klauern

MCP YNAB Server

by klauern

get_categories

Retrieve and format all transaction categories for a specified YNAB budget in Markdown, enabling organized financial tracking and analysis with the MCP YNAB Server.

Instructions

List all transaction categories for a given YNAB budget in Markdown format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budget_idYes

Implementation Reference

  • The primary handler for the 'get_categories' MCP tool. It fetches categories from the YNAB API using CategoriesApi, processes them into groups, formats budgeted and activity amounts, and returns a Markdown table representation.
    @mcp.tool() async def get_categories(budget_id: str) -> str: """List all transaction categories for a given YNAB budget in Markdown format.""" async with await get_ynab_client() as client: categories_api = CategoriesApi(client) response = categories_api.get_categories(budget_id) groups = response.data.category_groups markdown = "# YNAB Categories\n\n" headers = ["Category ID", "Category Name", "Budgeted", "Activity"] align = ["left", "left", "right", "right"] for group in groups: if isinstance(group, CategoryGroupWithCategories): categories_list = group.categories group_name = group.name else: group_dict = cast(Dict[str, Any], group.to_dict()) categories_list = group_dict["categories"] group_name = group_dict["name"] if not categories_list: continue markdown += f"## {group_name}\n\n" rows = [] for category in categories_list: cat_id, name, budgeted, activity = _process_category_data(category) budgeted_dollars = float(budgeted) / 1000 if budgeted else 0 activity_dollars = float(activity) / 1000 if activity else 0 rows.append( [ cat_id, name, _format_dollar_amount(budgeted_dollars), _format_dollar_amount(activity_dollars), ] ) table_md = _build_markdown_table(rows, headers, align) markdown += table_md + "\n" return markdown
  • Helper function used by get_categories to extract and normalize category data from either Category objects or dicts.
    def _process_category_data(category: Category | Dict[str, Any]) -> tuple[str, str, float, float]: """Process category data and return tuple of (id, name, budgeted, activity).""" if isinstance(category, Category): return category.id, category.name, category.budgeted, category.activity cat_dict = cast(Dict[str, Any], category) return cat_dict["id"], cat_dict["name"], cat_dict["budgeted"], cat_dict["activity"]
  • Helper function used by get_categories to format dollar amounts with signs and commas.
    def _format_dollar_amount(amount: float) -> str: """Format a dollar amount with proper sign and formatting.""" amount_str = f"${abs(amount):,.2f}" return f"-{amount_str}" if amount < 0 else amount_str
  • The @mcp.tool() decorator registers the get_categories function as an MCP tool with the name 'get_categories'.
    @mcp.tool() async def get_categories(budget_id: str) -> str: """List all transaction categories for a given YNAB budget in Markdown format.""" async with await get_ynab_client() as client: categories_api = CategoriesApi(client) response = categories_api.get_categories(budget_id) groups = response.data.category_groups markdown = "# YNAB Categories\n\n" headers = ["Category ID", "Category Name", "Budgeted", "Activity"] align = ["left", "left", "right", "right"] for group in groups: if isinstance(group, CategoryGroupWithCategories): categories_list = group.categories group_name = group.name else: group_dict = cast(Dict[str, Any], group.to_dict()) categories_list = group_dict["categories"] group_name = group_dict["name"] if not categories_list: continue markdown += f"## {group_name}\n\n" rows = [] for category in categories_list: cat_id, name, budgeted, activity = _process_category_data(category) budgeted_dollars = float(budgeted) / 1000 if budgeted else 0 activity_dollars = float(activity) / 1000 if activity else 0 rows.append( [ cat_id, name, _format_dollar_amount(budgeted_dollars), _format_dollar_amount(activity_dollars), ] ) table_md = _build_markdown_table(rows, headers, align) markdown += table_md + "\n" return markdown

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

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