Skip to main content
Glama

clear_old_cache

Remove expired weather cache entries older than a specified maximum age in minutes, freeing storage and ensuring data freshness.

Instructions

Clear expired weather cache entries.

Args: max_age_minutes: Maximum age in minutes before considering expired

Returns: Status message with number of entries removed

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_age_minutesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual implementation of clear_expired_cache (the helper called by clear_old_cache). Iterates over weather_cache dict, finds entries older than max_age_minutes, deletes them, and returns the count.
    def clear_expired_cache(self, max_age_minutes: int = 60) -> int:
        """Clear expired cache entries.
    
        Args:
            max_age_minutes: Maximum age before considering expired
    
        Returns:
            Number of entries removed
        """
        now = datetime.now(tz=timezone.utc)
        expired_keys = [
            key
            for key, value in self.weather_cache.items()
            if now - value["timestamp"] > timedelta(minutes=max_age_minutes)
        ]
    
        for key in expired_keys:
            del self.weather_cache[key]
    
        return len(expired_keys)
  • The MCP tool handler 'clear_old_cache' decorated with @mcp.tool(). Accepts max_age_minutes parameter, delegates to conversation_tools.clear_expired_cache(), and returns a status message.
    @mcp.tool()
    def clear_old_cache(max_age_minutes: int = 60) -> str:
        """Clear expired weather cache entries.
    
        Args:
            max_age_minutes: Maximum age in minutes before considering expired
    
        Returns:
            Status message with number of entries removed
        """
        removed = conversation_tools.clear_expired_cache(max_age_minutes)
        return f"Cleared {removed} expired cache entries older than {max_age_minutes} minutes"
  • Registration of the 'clear_old_cache' tool via the @mcp.tool() decorator on the function definition inside create_server().
    @mcp.tool()
    def clear_old_cache(max_age_minutes: int = 60) -> str:
        """Clear expired weather cache entries.
    
        Args:
            max_age_minutes: Maximum age in minutes before considering expired
    
        Returns:
            Status message with number of entries removed
        """
        removed = conversation_tools.clear_expired_cache(max_age_minutes)
        return f"Cleared {removed} expired cache entries older than {max_age_minutes} minutes"
  • Helper method get_cached_weather() used by other tools to check cache age; related to the caching system that clear_old_cache manages.
    def get_cached_weather(self, cache_key: str, max_age_minutes: int = 60) -> str | None:
        """Get cached weather data if still fresh.
    
        Args:
            cache_key: Cache identifier to lookup
            max_age_minutes: Maximum age in minutes before cache expires
    
        Returns:
            Cached data if fresh, None if expired or not found
        """
        if cache_key not in self.weather_cache:
            return None
    
        cached = self.weather_cache[cache_key]
        age = datetime.now(tz=timezone.utc) - cached["timestamp"]
    
        if age <= timedelta(minutes=max_age_minutes):
            cached_data: str = cached["data"]
            return cached_data
    
        # Cache expired, remove it
        del self.weather_cache[cache_key]
        return None

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A3.9/5.0
Behavior3/5

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

With no annotations provided, the description indicates a destructive action (clearing cache) and mentions the return value (status with count). However, it lacks details on side effects (e.g., impact on other users, reversibility) or safety considerations beyond 'expired' entries.

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

Conciseness4/5

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

The description is concise with a clear one-liner followed by structured args/returns. It could be even more concise but is well-organized and readable.

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's simplicity (single parameter, output schema exists), the description covers its core function and return value adequately. However, it does not elaborate on edge cases or behavior when no entries are expired.

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 description adds meaningful context for the only parameter, 'max_age_minutes', beyond the schema's type and default, explaining it as 'Maximum age in minutes before considering expired'. This compensates for the 0% schema description coverage.

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 action ('Clear expired weather cache entries') with a specific verb and resource, distinguishing it from sibling read tools like get_alerts, get_current_time, and get_forecast.

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 for cache maintenance but does not explicitly state when to use this tool over alternatives (e.g., after forecast fetches) or provide any usage restrictions or prerequisites.

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