Skip to main content
Glama
haasonsaas

MCP Utility Tools

by haasonsaas

cache_put

Store values in cache with expiration times to improve performance by reducing repeated computations and API calls.

Instructions

Store a value in the cache with TTL. Useful for caching API responses, computed values, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesCache key
valueYesValue to cache (any JSON-serializable data)
ttl_secondsNoTime to live in seconds
namespaceNoOptional namespace to prevent key collisionsdefault

Implementation Reference

  • Handler for cache_put tool: extracts key, value, optional ttl_seconds from args, computes expiresAt, stores in global cache Map, returns JSON success response with details.
    case "cache_put": {
      const { key, value, ttl_seconds = 300 } = args as any;
      
      const expiresAt = Date.now() + (ttl_seconds * 1000);
      cache.set(key, { value, expiresAt });
    
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            success: true,
            key,
            ttl_seconds,
            expires_at: new Date(expiresAt).toISOString()
          })
        }]
      };
    }
  • src/index.ts:98-121 (registration)
    Registration of the cache_put tool in the tools array used by ListToolsRequestSchema handler, includes name, description, and inputSchema.
    {
      name: "cache_put",
      description: "Store a value in the cache with TTL",
      inputSchema: {
        type: "object",
        properties: {
          key: {
            type: "string",
            description: "Cache key"
          },
          value: {
            description: "Value to cache (any JSON-serializable data)"
          },
          ttl_seconds: {
            type: "number",
            description: "Time to live in seconds",
            default: 300,
            minimum: 1,
            maximum: 86400 // 24 hours
          }
        },
        required: ["key", "value"]
      }
    },
  • Handler for cache_put tool in v2: supports namespace via getCacheKey, stores with TTL in cache, returns success with namespace and cache_size.
    case "cache_put": {
      const { key, value, ttl_seconds = 300, namespace = "default" } = args as any;
      const cacheKey = getCacheKey(key, namespace);
      
      const expiresAt = Date.now() + (ttl_seconds * 1000);
      cache.set(cacheKey, { value, expiresAt });
    
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            success: true,
            key,
            namespace,
            ttl_seconds,
            expires_at: new Date(expiresAt).toISOString(),
            cache_size: cache.size
          })
        }]
      };
    }
  • Registration of cache_put tool in v2 tools array, adds optional namespace to schema.
    {
      name: "cache_put",
      description: "Store a value in the cache with TTL. Useful for caching API responses, computed values, etc.",
      inputSchema: {
        type: "object",
        properties: {
          key: {
            type: "string",
            description: "Cache key"
          },
          value: {
            description: "Value to cache (any JSON-serializable data)"
          },
          ttl_seconds: {
            type: "number",
            description: "Time to live in seconds",
            default: 300,
            minimum: 1,
            maximum: 86400 // 24 hours
          },
          namespace: {
            type: "string",
            description: "Optional namespace to prevent key collisions",
            default: "default"
          }
        },
        required: ["key", "value"]
      }
    },
  • Global cache storage helper: defines CacheEntry interface, initializes Map, and sets up periodic cleanup of expired entries. Used by all cache_* tools.
    // Cache storage with TTL support
    interface CacheEntry {
      value: any;
      expiresAt: number;
    }
    
    const cache = new Map<string, CacheEntry>();
    
    // Clean up expired cache entries periodically
    setInterval(() => {
      const now = Date.now();
      for (const [key, entry] of cache.entries()) {
        if (entry.expiresAt <= now) {
          cache.delete(key);
        }
      }
    }, 60000); // Clean every minute
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 mentions TTL (time-to-live) which implies expiration behavior, but doesn't describe other critical traits: whether this overwrites existing keys, what happens on failure, if there are size limits, or how the cache is scoped (e.g., per-user vs. global). For a write operation with zero annotation coverage, this leaves significant gaps.

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 extremely concise—two short sentences with zero waste. The first sentence states the core purpose, and the second provides helpful usage examples. Every word earns its place, and it's front-loaded with the essential information.

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?

For a write operation with 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like overwrite behavior, error conditions, or response format. While the schema handles parameters well, the description should compensate for the lack of annotations by providing more operational context.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already fully documents all 4 parameters (key, value, ttl_seconds, namespace). The description adds no parameter-specific semantics beyond what's in the schema—it doesn't explain key formatting, value serialization constraints, or namespace usage. Baseline 3 is appropriate when the schema does all the work.

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

Purpose4/5

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

The description clearly states the tool's purpose with a specific verb ('Store') and resource ('value in the cache'), and mentions TTL. It distinguishes from siblings like cache_get (retrieve) and cache_delete/clear (remove), but doesn't explicitly contrast them. The 'useful for' examples add helpful context without being essential to the core purpose.

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 provides implied usage guidance through the 'useful for' examples (caching API responses, computed values), suggesting when this tool might be appropriate. However, it doesn't explicitly state when to use this vs. alternatives like cache_get (for retrieval) or cache_delete (for removal), nor does it mention prerequisites or exclusions.

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

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