Skip to main content
Glama
klauern

MCP YNAB Server

by klauern

cache_categories

Store YNAB budget categories locally to reduce API calls and improve data access speed for financial tracking.

Instructions

Cache all categories for a given YNAB budget ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budget_idYes

Implementation Reference

  • The handler function for the MCP tool 'cache_categories'. It fetches all categories from the YNAB API for the specified budget_id and caches them using the YNABResources.cache_categories helper method. The @mcp.tool() decorator registers this function as an MCP tool.
    @mcp.tool() async def cache_categories(budget_id: str) -> str: """Cache all categories for a given YNAB budget ID.""" async with await get_ynab_client() as client: categories_api = CategoriesApi(client) response = categories_api.get_categories(budget_id) groups = response.data.category_groups categories = [] for group in groups: if isinstance(group, CategoryGroupWithCategories): categories.extend(group.categories) ynab_resources.cache_categories(budget_id, [cat.to_dict() for cat in categories]) return f"Categories cached for budget ID {budget_id}"
  • Supporting helper method in the YNABResources class that stores the provided categories in a JSON cache file (BUDGET_CATEGORY_CACHE_FILE) for later retrieval via the 'ynab://categories/{budget_id}' MCP resource.
    def cache_categories(self, budget_id: str, categories: List[Dict[str, Any]]) -> None: """Cache categories for a budget ID.""" self._category_cache[budget_id] = [ { "id": cat.get("id"), "name": cat.get("name"), "group": cat.get("category_group_name"), } for cat in categories ] _save_json_file(BUDGET_CATEGORY_CACHE_FILE, self._category_cache)
  • The @mcp.tool() decorator registers the cache_categories 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/klauern/mcp-ynab'

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