Skip to main content
Glama
clsung

Taiwan Stock Agent

by clsung

invalidate_cache

Clear cached Taiwan stock market data to retrieve updated information for accurate analysis and decision-making.

Instructions

Invalidate resource cache for fresh data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resource_patternNo

Implementation Reference

  • MCP tool handler for 'invalidate_cache' that delegates to resource_manager.invalidate_cache and formats the response with cache statistics.
    @mcp.tool(name="invalidate_cache",
              description="Invalidate resource cache for fresh data")
    async def invalidate_cache_tool(resource_pattern: Optional[str] = None) -> Dict[str, Any]:
        """Invalidate resource cache."""
        try:
            invalidated_count = resource_manager.invalidate_cache(resource_pattern)
            cache_stats = resource_manager.get_cache_stats()
            
            return {
                "pattern": resource_pattern or "all",
                "invalidated_entries": invalidated_count,
                "cache_statistics": cache_stats,
                "_metadata": {
                    "source": "tw-stock-agent",
                    "timestamp": datetime.now().isoformat(),
                    "data_type": "cache_management"
                }
            }
        except Exception as e:
            logger.error(f"Failed to invalidate cache: {e}")
            return {
                "pattern": resource_pattern or "all",
                "invalidated_entries": 0,
                "error": str(e),
                "_metadata": {
                    "source": "tw-stock-agent",
                    "timestamp": datetime.now().isoformat(),
                    "data_type": "cache_management",
                    "has_error": True
                }
            }
  • Core implementation of cache invalidation in ResourceManager class, clearing all or pattern-matched cache entries.
    def invalidate_cache(self, resource_pattern: Optional[str] = None) -> int:
        """
        Invalidate cached resources.
        
        Args:
            resource_pattern: Optional pattern to match specific resources
            
        Returns:
            Number of cache entries invalidated
        """
        if resource_pattern is None:
            # Clear entire cache
            count = len(self.cache)
            self.cache.clear()
            logger.info(f"Invalidated entire resource cache ({count} entries)")
            return count
        else:
            # Clear matching entries
            keys_to_remove = [
                key for key in self.cache.keys()
                if resource_pattern in key
            ]
            for key in keys_to_remove:
                del self.cache[key]
            logger.info(f"Invalidated {len(keys_to_remove)} cache entries matching '{resource_pattern}'")
            return len(keys_to_remove)
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 of behavioral disclosure. It states the tool invalidates cache 'for fresh data', implying a mutation that refreshes data, but doesn't specify what gets invalidated (e.g., all cache, specific resources), whether it's destructive, permission requirements, or rate limits. This leaves critical behavioral traits unclear for a mutation tool.

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, efficient sentence with no wasted words. It's front-loaded with the core action ('Invalidate resource cache') and purpose ('for fresh data'), making it easy to parse quickly. Every part of the sentence contributes to understanding the tool's intent.

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

Completeness2/5

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

Given the tool's complexity (a mutation operation with one parameter), lack of annotations, no output schema, and 0% schema coverage, the description is incomplete. It doesn't cover parameter usage, behavioral details like side effects, or what happens after invalidation. For a cache-invalidation tool, this leaves too many gaps for reliable agent use.

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

Parameters2/5

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

The schema description coverage is 0%, with one parameter ('resource_pattern') undocumented in the schema. The description doesn't mention parameters at all, failing to compensate for the schema gap. It doesn't explain what 'resource_pattern' means, its format, or how it affects the invalidation, leaving the parameter's purpose ambiguous.

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

Purpose3/5

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

The description 'Invalidate resource cache for fresh data' states the tool's purpose with a specific verb ('invalidate') and resource ('cache'), but it's somewhat vague about what exactly gets invalidated. It doesn't clearly distinguish this from sibling tools like 'list_resources' or 'subscribe_resource' which might also involve cache operations. The purpose is understandable but lacks precision about scope and boundaries.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., after data updates), exclusions, or how it relates to sibling tools like 'get_realtime_data' or 'list_resources'. Without any usage context, the agent must infer when this tool is appropriate, which could lead to misuse.

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/clsung/tw-stock-agent'

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