retrieve_data
Retrieve cached data using a key to access stored information and reduce redundant token usage in 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)MCP tool handler for 'retrieve_data': extracts key from arguments, retrieves value using CacheManager.get(), returns JSON string or error message 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:124-133 (schema)Input schema definition for the retrieve_data tool, specifying required 'key' parameter.inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'Key of the cached data to retrieve', }, }, required: ['key'], },
- src/index.ts:121-134 (registration)Registration of the retrieve_data tool in the ListTools response, including name, description, and schema.{ 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)CacheManager.get method: retrieves entry by key, checks expiration, updates access time and statistics, returns value or undefined.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; }