cache_categories
Cache all categories for a specified YNAB budget ID to streamline access and enhance data retrieval within the MCP YNAB Server.
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 main MCP tool handler for 'cache_categories'. Fetches all categories from the YNAB API for the given budget_id and caches them using the YNABResources helper method.@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 on YNABResources class that stores the provided categories in the local JSON cache file for quick retrieval.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)
- src/mcp_ynab/server.py:685-685 (registration)The @mcp.tool() decorator registers the cache_categories function as an MCP tool.@mcp.tool()