Skip to main content
Glama
haasonsaas

MCP Utility Tools

by haasonsaas

cache_clear

Clear all cached entries or specific namespaces to free memory and ensure data freshness in MCP workflows.

Instructions

Clear all entries from the cache or a specific namespace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceNoClear only this namespace, or all if not specified

Implementation Reference

  • Handler implementation for the cache_clear tool. Clears the entire cache using cache.clear() and returns the number of entries cleared before clearing.
    case "cache_clear": {
      const size = cache.size;
      cache.clear();
      
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            success: true,
            cleared_entries: size
          })
        }]
      };
    }
  • Enhanced handler for cache_clear tool supporting optional namespace clearing. Iterates and deletes keys with matching prefix if namespace provided, otherwise clears all. Returns count of cleared entries.
    case "cache_clear": {
      const { namespace } = args as any;
      
      if (namespace) {
        let cleared = 0;
        const prefix = `${namespace}:`;
        for (const key of cache.keys()) {
          if (key.startsWith(prefix)) {
            cache.delete(key);
            cleared++;
          }
        }
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              success: true,
              namespace,
              cleared_entries: cleared
            })
          }]
        };
      } else {
        const size = cache.size;
        cache.clear();
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              success: true,
              cleared_entries: size
            })
          }]
        };
      }
    }
  • src/index.ts:136-143 (registration)
    Tool registration in the tools list, including name, description, and empty input schema.
    {
      name: "cache_clear",
      description: "Clear all entries from the cache",
      inputSchema: {
        type: "object",
        properties: {}
      }
    },
  • Tool registration for v2 with support for namespace parameter in input schema.
    {
      name: "cache_clear",
      description: "Clear all entries from the cache or a specific namespace",
      inputSchema: {
        type: "object",
        properties: {
          namespace: {
            type: "string",
            description: "Clear only this namespace, or all if not specified"
          }
        }
      }
    },
  • Cache storage Map used by cache_clear and other cache tools. Defined identically in index-v2.ts.
    const cache = new Map<string, CacheEntry>();

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/haasonsaas/mcp-utility-tools'

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