Skip to content

Cache Tools

The YNAB MCP server caches your budget list to minimize API calls and stay within YNAB's rate limits. Cache tools let you clear this cache when you need fresh data -- for example, after creating a new budget in the YNAB app or if something looks stale.

Most of the time you won't need to touch the cache. Transaction and category data is fetched fresh on each request. The cache primarily covers the budget list lookup, which changes infrequently.

Usage Examples

You: Clear the YNAB cache.

Claude calls clear_cache and responds:

All caches cleared.

You: I just created a new budget in YNAB but it's not showing up.

Claude calls clear_cache to refresh, then manage_budgets with action list:

Cache cleared. Here are your current budgets: 3 budgets found: - My Budget (Last modified: 2026-03-06) - Vacation Fund (Last modified: 2026-02-15) - New Side Project (Last modified: 2026-03-06)

When to Clear the Cache

  • You created or deleted a budget in the YNAB app or website
  • Budget names or settings were changed outside of MCP
  • You're seeing budget list data that doesn't match what's in YNAB

You can clear the cache for a specific budget by ID, or clear everything at once.


API Reference

clear_cache

clear_cache(ctx: Context, budget_id: str | None = None) -> str

Clear cached YNAB data to force fresh API requests.

Use this if you've made changes in the YNAB app or web interface and want to ensure the latest data is fetched.

Parameters:

  • ctx (Context) –

    MCP context.

  • budget_id (str | None, default: None ) –

    Optional budget ID to clear cache for. If not provided, clears all caches.

Returns:

  • str

    Confirmation message.

Source code in src/ynaa_mcp/tools/cache.py
@mcp.tool
def clear_cache(
    ctx: Context,
    budget_id: str | None = None,
) -> str:
    """Clear cached YNAB data to force fresh API requests.

    Use this if you've made changes in the YNAB app or web interface
    and want to ensure the latest data is fetched.

    Args:
        ctx: MCP context.
        budget_id: Optional budget ID to clear cache for.
            If not provided, clears all caches.

    Returns:
        Confirmation message.
    """
    app = cast("AppContext", ctx.lifespan_context)
    if budget_id:
        app.cache.invalidate_budget(budget_id)
        return f"Cache cleared for budget {budget_id}."
    app.cache.clear()
    return "All caches cleared."