Skip to main content
Glama
klauern

MCP YNAB Server

by klauern

get_categories

Retrieve all transaction categories for a YNAB budget and display them in Markdown format to organize and analyze spending patterns.

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' tool, registered via @mcp.tool() decorator. Fetches category groups from YNAB's CategoriesApi, processes each category's budgeted and activity amounts, formats into Markdown tables per group, and returns the formatted string.
    @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 type-convert id, name, budgeted, and activity from either Category model or dict.
    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 budgeted and activity amounts as currency strings with negative sign prefix.
    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
  • General helper function used by get_categories (and others) to generate Markdown tables from row data, handling alignments and column widths.
    def _build_markdown_table(
        rows: List[List[str]], headers: List[str], alignments: Optional[List[str]] = None
    ) -> str:
        """Build a markdown table from rows and headers."""
        if not rows:
            return _get_empty_table(headers)
    
        alignments = alignments if alignments is not None else ["left"] * len(headers)
        col_count = len(headers)
        widths = _get_column_widths(headers, rows, col_count)
    
        header_line = _format_table_line(headers, widths, alignments)
        sep_line = "|" + "|".join("-" * (w + 1) for w in widths) + "|\n"
    
        row_lines = "".join(_format_table_line(row, widths, alignments) for row in rows)
        return header_line + sep_line + row_lines
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is a read operation ('List'), implying it's non-destructive, but doesn't cover other important aspects like authentication requirements, rate limits, error handling, or what happens if the budget_id is invalid. This is a significant gap for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently conveys the core purpose, resource, and output format without any wasted words. It's front-loaded with the main action and appropriately sized for its complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations, no output schema, and minimal parameter guidance, the description is incomplete. It adequately states what the tool does but fails to provide necessary context for safe and effective use, such as behavioral traits, error conditions, or output structure beyond 'Markdown format'.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter-specific information beyond what's in the schema (which has 0% description coverage). It mentions 'for a given YNAB budget', which implicitly relates to the 'budget_id' parameter, but doesn't explain its format, sourcing, or constraints. With one parameter and low schema coverage, the description provides minimal compensation, meeting the baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List all transaction categories') and resource ('for a given YNAB budget'), making the purpose immediately understandable. It also specifies the output format ('in Markdown format'), which adds useful detail. However, it doesn't explicitly differentiate from sibling tools like 'cache_categories' or 'get_budgets', preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a budget_id first), exclusions, or comparisons to siblings like 'cache_categories' or 'get_transactions'. This leaves the agent with minimal context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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