store
Compress data with auto-selected algorithm and save it under a key for later retrieval. Retrieve decompressed data using the key. Ideal for agents needing compressed key-value storage.
Instructions
Compress data and store it to disk with a key. Retrieve later with the key. Like a compressed key-value store for agents.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Data to compress and store | |
| name | No | Key name for retrieval. Auto-generated if not provided. | |
| algorithm | No | Compression algorithm |
Implementation Reference
- index.js:427-461 (handler)handleStore — The main handler for the 'store' tool. Compresses data using the specified algorithm (or auto), saves the compressed data to disk as a .bin file, writes metadata as a .json file, and returns the key and storage details.
handleStore(args) { const { data, name, algorithm = 'auto' } = args; if (!data) return { error: 'Missing "data" parameter' }; const key = name || createHash('sha256').update(data).digest('hex').slice(0, 16); const result = this.compressData(data, algorithm); const metadata = { key, algorithm: result.algorithm, originalSize: result.originalSize, compressedSize: result.compressedSize, ratio: result.ratio, storedAt: new Date().toISOString(), hash: createHash('sha256').update(data).digest('hex'), }; const dataPath = join(STORE_DIR, `${key}.bin`); const metaPath = join(STORE_DIR, `${key}.json`); writeFileSync(dataPath, result.compressed); writeFileSync(metaPath, JSON.stringify(metadata, null, 2)); this.stats.total_compressed++; this.stats.total_saved_bytes += result.originalSize - result.compressedSize; this.stats.operations++; return { key, stored_at: dataPath, original_size: result.originalSize, compressed_size: result.compressedSize, ratio: `${result.ratio.toFixed(1)}x`, saved: `${result.originalSize - result.compressedSize} bytes` }; } - index.js:594-605 (schema)Tool definition and input schema for 'store' — defines the name, description, and JSON Schema input validation (data required, optional name and algorithm).
name: 'store', description: 'Compress data and store it to disk with a key. Retrieve later with the key. Like a compressed key-value store for agents.', inputSchema: { type: 'object', properties: { data: { type: 'string', description: 'Data to compress and store' }, name: { type: 'string', description: 'Key name for retrieval. Auto-generated if not provided.' }, algorithm: { type: 'string', enum: ['auto', 'gzip', 'brotli', 'deflate'], description: 'Compression algorithm' } }, required: ['data'] } }, - index.js:686-686 (registration)Tool dispatch — The 'store' case in the tools/call handler that routes to handleStore.
case 'store': result = this.handleStore(args); break; - index.js:198-198 (helper)STORE_DIR constant — defines the storage directory (~/.mcp-compress) where compressed data and metadata files are written.
const STORE_DIR = join(homedir(), '.mcp-compress');