cache_categories
Store all YNAB categories for a specific budget ID using the Model Context Protocol, enabling efficient access and management of budget data.
Instructions
Cache all categories for a given YNAB budget ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| budget_id | Yes |
Implementation Reference
- src/mcp_ynab/server.py:685-699 (handler)The handler function for the 'cache_categories' MCP tool. It fetches all categories from the YNAB API for the given budget_id and caches them using the helper method. Registered via @mcp.tool() decorator.@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}"
- src/mcp_ynab/server.py:264-275 (helper)Helper method in the YNABResources class that persists the categories to a JSON cache file for the specified budget_id.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)