Skip to main content
Glama
haasonsaas

MCP Utility Tools

by haasonsaas

cache_get

Retrieve cached data by key to access stored values and reduce redundant processing in MCP workflows.

Instructions

Get a value from the cache by key. Returns null if not found or expired.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesCache key to retrieve
namespaceNoOptional namespace to prevent key collisionsdefault

Implementation Reference

  • The handler for the 'cache_get' tool. It retrieves the cache entry by key, checks if it exists and is not expired, and returns a JSON response with the value or indication if not found or expired.
    case "cache_get": {
      const { key } = args as { key: string };
      
      const entry = cache.get(key);
      if (!entry) {
        return {
          content: [{
            type: "text",
            text: JSON.stringify({ found: false, key })
          }]
        };
      }
    
      // Check if expired
      if (entry.expiresAt <= Date.now()) {
        cache.delete(key);
        return {
          content: [{
            type: "text",
            text: JSON.stringify({ found: false, key, reason: "expired" })
          }]
        };
      }
    
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            found: true,
            key,
            value: entry.value,
            expires_in_seconds: Math.floor((entry.expiresAt - Date.now()) / 1000)
          })
        }]
      };
    }
  • src/index.ts:84-97 (registration)
    The tool registration object in the tools array, which includes the name, description, and input schema. This is returned by the ListTools handler.
    {
      name: "cache_get",
      description: "Get a value from the cache by key",
      inputSchema: {
        type: "object",
        properties: {
          key: {
            type: "string",
            description: "Cache key to retrieve"
          }
        },
        required: ["key"]
      }
    },
  • The input schema defining the expected arguments for the cache_get tool: a required 'key' string.
    inputSchema: {
      type: "object",
      properties: {
        key: {
          type: "string",
          description: "Cache key to retrieve"
        }
      },
      required: ["key"]
    }
  • The CacheEntry interface and cache Map storage used by the cache_get handler and other cache tools.
    interface CacheEntry {
      value: any;
      expiresAt: number;
    }
    
    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