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
| Name | Required | Description | Default |
|---|---|---|---|
| budget_id | Yes |
Implementation Reference
- src/mcp_ynab/server.py:685-699 (handler)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}"
- src/mcp_ynab/server.py:264-275 (helper)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)
- src/mcp_ynab/server.py:685-685 (registration)The @mcp.tool() decorator registers the cache_categories function as an MCP tool.@mcp.tool()