Skip to main content
Glama

clear_cache

Clears persistent device cache to resolve issues when devices have changed or cache is corrupted. Removes cache file and in-memory cache. Run scan_network after to rebuild.

Instructions

Clear the persistent device cache.

Removes the cache file and clears in-memory cache. Useful when devices have changed or cache is corrupted. Run scan_network after clearing to rebuild the cache.

Returns

Dictionary containing:
- success: Whether cache was cleared successfully
- message: Descriptive message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The clear_cache tool handler function. Decorated with @mcp.tool(), it clears both the persistent disk cache (via _cache_manager.clear()) and the in-memory device cache (_device_cache.clear()). Returns success/error response dict.
    @mcp.tool()
    async def clear_cache() -> dict[str, Any]:
        """Clear the persistent device cache.
    
        Removes the cache file and clears in-memory cache. Useful when devices
        have changed or cache is corrupted. Run scan_network after clearing
        to rebuild the cache.
    
        Returns
        -------
            Dictionary containing:
            - success: Whether cache was cleared successfully
            - message: Descriptive message
    
        """
        try:
            # Clear persistent cache
            cache_cleared = _cache_manager.clear()
    
            # Clear in-memory cache
            _device_cache.clear()
    
            if cache_cleared:
                return {
                    "success": True,
                    "message": "Cache cleared successfully. Run scan_network to rebuild cache.",
                    "timestamp": time.time(),
                }
            return {
                "success": False,
                "error": "Failed to clear cache file",
                "timestamp": time.time(),
            }
    
        except Exception as e:
            logger.error(f"Error clearing cache: {e}", exc_info=True)
            return build_error_response(e, "Clear cache")
  • Tool registration via @mcp.tool() decorator on the clear_cache async function. This registers the function as an MCP tool named 'clear_cache'.
    @mcp.tool()
    async def clear_cache() -> dict[str, Any]:
  • The DeviceCache.clear() method called by the clear_cache handler. Deletes the cache JSON file from disk and resets the in-memory _cache dict.
    def clear(self) -> bool:
        """Clear the device cache (delete cache file).
    
        Returns
        -------
            True if cleared successfully, False otherwise
    
        """
        try:
            if self.cache_file.exists():
                self.cache_file.unlink()
                logger.info(f"Cleared cache file at {self.cache_file}")
    
            self._cache = {}
            return True
    
        except OSError as e:
            logger.error(f"Failed to clear cache at {self.cache_file}: {e}")
            return False
  • The clear_cache tool's input/output contract: no input parameters (empty), returns a dict with success (bool), message (str), and timestamp. On error returns error response via build_error_response.
    @mcp.tool()
    async def clear_cache() -> dict[str, Any]:
        """Clear the persistent device cache.
    
        Removes the cache file and clears in-memory cache. Useful when devices
        have changed or cache is corrupted. Run scan_network after clearing
        to rebuild the cache.
    
        Returns
        -------
            Dictionary containing:
            - success: Whether cache was cleared successfully
            - message: Descriptive message
    
        """
        try:
            # Clear persistent cache
            cache_cleared = _cache_manager.clear()
    
            # Clear in-memory cache
            _device_cache.clear()
    
            if cache_cleared:
                return {
                    "success": True,
                    "message": "Cache cleared successfully. Run scan_network to rebuild cache.",
                    "timestamp": time.time(),
                }
            return {
                "success": False,
                "error": "Failed to clear cache file",
                "timestamp": time.time(),
            }
    
        except Exception as e:
            logger.error(f"Error clearing cache: {e}", exc_info=True)
            return build_error_response(e, "Clear cache")
Behavior4/5

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

With no annotations, the description carries full behavioral disclosure burden. It states the tool removes the cache file and clears in-memory cache, and describes the return dictionary. This is transparent about the destructive action, but could mention idempotency or permission requirements.

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 concise: three short sentences plus a structured return value specification. It is front-loaded with the action and contains no redundant information. Every sentence serves a purpose.

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

Completeness5/5

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

Given no parameters, a simple output schema, and the context signals, the description fully covers purpose, usage guidance, and outcome. It explains when to use, what happens, and what to do next. No gaps remain.

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 input schema has zero parameters (100% coverage trivially). The description adds no parameter info, but none is needed. Baseline for 0 parameters is 4. The description could have explicitly stated 'no arguments required,' but not necessary.

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 clears the persistent device cache, specifying it removes the cache file and clears in-memory cache. It distinguishes itself from siblings like 'get_cache_info' (which reads cache) and 'scan_network' (which rebuilds cache), providing a specific verb and resource.

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

Usage Guidelines4/5

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

The description explicitly says when to use: 'when devices have changed or cache is corrupted.' It also suggests a follow-up step ('Run scan_network after clearing'). It does not explicitly mention when not to use, but the context implies it's for troubleshooting. This is clear enough for an agent, though exclusions would improve it.

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/apiarya/wemo-mcp-server'

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