Skip to main content
Glama
lumishoang

OpenRouter MCP Server

by lumishoang

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

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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."
  • 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:
  • 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}")
  • 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"]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. The description mentions 'force refresh' but does not disclose potential side effects (e.g., impact on ongoing requests, rate limits, or whether it is idempotent), leaving significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, front-loaded with the key action. Every word contributes to the meaning, with no unnecessary information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no parameters and an output schema exists, the description is largely complete for its purpose. It explains the action, and the output schema can document return values. However, it lacks any usage context or behavioral notes that could be useful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, so the input schema provides complete coverage. Per guidelines, baseline is 4. The description adds no additional parameter meaning, but that is acceptable given no parameters exist.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool refreshes the model cache from OpenRouter. The verb 'refresh' and resource 'model cache' are specific, and it distinguishes from sibling tools that compare, get, list, or search models.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when cache is stale but does not provide explicit guidance on when to use or when not to use, nor does it mention alternatives among siblings. The context is clear but lacks exclusions or comparisons.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/lumishoang/openrouter-mcp'

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