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
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Cache key to retrieve | |
| namespace | No | Optional namespace to prevent key collisions | default |
Implementation Reference
- src/index.ts:268-303 (handler)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"] } },
- src/index.ts:87-96 (schema)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"] }
- src/index.ts:13-18 (helper)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>();