store_data
Store data in a cache with optional expiration time to reduce redundant token usage in language model interactions.
Instructions
Store data in the cache with optional TTL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Unique identifier for the cached data | |
| value | Yes | Data to cache | |
| ttl | No | Time-to-live in seconds (optional) |
Implementation Reference
- src/index.ts:162-177 (handler)MCP tool handler for 'store_data': destructures arguments and calls CacheManager.set(key, value, ttl), returns success message.case 'store_data': { const { key, value, ttl } = request.params.arguments as { key: string; value: any; ttl?: number; }; this.cacheManager.set(key, value, ttl); return { content: [ { type: 'text', text: `Successfully stored data with key: ${key}`, }, ], }; }
- src/index.ts:102-119 (schema)Input schema for store_data tool defining key (string, required), value (any, required), ttl (number, optional).inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'Unique identifier for the cached data', }, value: { type: 'any', description: 'Data to cache', }, ttl: { type: 'number', description: 'Time-to-live in seconds (optional)', }, }, required: ['key', 'value'], },
- src/index.ts:99-120 (registration)Tool registration in ListTools response including name, description, and input schema for 'store_data'.{ name: 'store_data', description: 'Store data in the cache with optional TTL', inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'Unique identifier for the cached data', }, value: { type: 'any', description: 'Data to cache', }, ttl: { type: 'number', description: 'Time-to-live in seconds (optional)', }, }, required: ['key', 'value'], }, },
- src/CacheManager.ts:35-60 (helper)CacheManager.set method: core implementation storing data with TTL, size estimation, memory limit enforcement via LRU eviction, and stats updates.set(key: string, value: any, ttl?: number): void { const startTime = performance.now(); // Calculate approximate size in bytes const size = this.calculateSize(value); // Check if adding this entry would exceed memory limit if (this.stats.memoryUsage + size > this.config.maxMemory) { this.enforceMemoryLimit(size); } const entry: CacheEntry = { value, created: Date.now(), lastAccessed: Date.now(), ttl: ttl ?? this.config.defaultTTL, size }; this.cache.set(key, entry); this.stats.totalEntries = this.cache.size; this.stats.memoryUsage += size; const endTime = performance.now(); this.updateAccessTime(endTime - startTime); }