retrieve_data
Retrieve cached data from the Memory Cache Server using a specific key to access stored information during language model interactions.
Instructions
Retrieve data from the cache
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key of the cached data to retrieve |
Implementation Reference
- src/index.ts:179-201 (handler)The main handler for the 'retrieve_data' tool. Extracts the key from the request arguments, retrieves the value using CacheManager.get(key), and returns the JSON-stringified value or an error if not found.case 'retrieve_data': { const { key } = request.params.arguments as { key: string }; const value = this.cacheManager.get(key); if (value === undefined) { return { content: [ { type: 'text', text: `No data found for key: ${key}`, }, ], isError: true, }; } return { content: [ { type: 'text', text: JSON.stringify(value, null, 2), }, ], }; }
- src/index.ts:122-133 (schema)Input schema for the 'retrieve_data' tool, defining that a 'key' string is required. Part of the tool registration in ListToolsRequestSchema handler.name: 'retrieve_data', description: 'Retrieve data from the cache', inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'Key of the cached data to retrieve', }, }, required: ['key'], },
- src/CacheManager.ts:62-89 (helper)Core retrieval logic in CacheManager.get(key): fetches from Map, checks expiration, updates access time and statistics, returns the cached value.get(key: string): any { const startTime = performance.now(); const entry = this.cache.get(key); if (!entry) { this.stats.misses++; this.updateHitRate(); return undefined; } // Check if entry has expired if (this.isExpired(entry)) { this.delete(key); this.stats.misses++; this.updateHitRate(); return undefined; } // Update last accessed time entry.lastAccessed = Date.now(); this.stats.hits++; this.updateHitRate(); const endTime = performance.now(); this.updateAccessTime(endTime - startTime); return entry.value; }