refresh_cache
Force update the model cache from OpenRouter to retrieve the most current model details, pricing, and capabilities.
Instructions
Force refresh the model cache from OpenRouter.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/openrouter_mcp/server.py:233-238 (handler)The refresh_cache() function is the tool handler. It invalidates the cache by setting _cache['data'] to None, then calls fetch_models(force=True) to re-fetch data from OpenRouter, returning a confirmation string with the count of loaded models.
@mcp.tool() def refresh_cache() -> str: """Force refresh the model cache from OpenRouter.""" _cache["data"] = None models = fetch_models(force=True) return f"Cache refreshed. {len(models)} models loaded." - src/openrouter_mcp/server.py:233-234 (registration)The tool is registered as an MCP tool via the @mcp.tool() decorator on line 233, which is part of the FastMCP framework.
@mcp.tool() def refresh_cache() -> str: - src/openrouter_mcp/server.py:34-52 (helper)The fetch_models() helper function is called by refresh_cache() with force=True. It handles the actual API call to OpenRouter to fetch models data with caching logic.
def fetch_models(force=False) -> list[dict]: """Fetch model list from OpenRouter with caching.""" now = time.time() if _cache["data"] is not None and (now - _cache["ts"]) < CACHE_TTL and not force: return _cache["data"] headers = {"Accept": "application/json"} if OR_API_KEY: headers["Authorization"] = f"Bearer {OR_API_KEY}" req = Request(OR_MODELS_URL, headers=headers) try: with urlopen(req, timeout=30) as resp: body = json.loads(resp.read()) _cache["data"] = body.get("data", []) _cache["ts"] = now return _cache["data"] except URLError as e: raise RuntimeError(f"Failed to fetch OpenRouter models: {e}") - src/openrouter_mcp/__init__.py:5-7 (registration)The refresh_cache function is imported from .server and listed in __all__, making it part of the public API of the openrouter_mcp package.
from .server import main, fetch_models, list_models, get_model, search_models, compare_models, refresh_cache __all__ = ["main", "fetch_models", "list_models", "get_model", "search_models", "compare_models", "refresh_cache"]