compress
Compress text, JSON, or CSV data to reduce size and optimize storage. Automatically selects the best compression algorithm and returns base64-encoded results with compression ratio.
Instructions
Compress text/JSON/CSV data. Returns base64-encoded compressed data with compression ratio. Use algorithm="auto" to pick the best compression.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | The data to compress (text, JSON, CSV, etc.) | |
| algorithm | No | Compression algorithm. Default: auto (picks best) |
Implementation Reference
- index.js:120-139 (handler)The handler function for the 'compress' tool, which processes input data using chosen compression algorithms and returns statistics.
handleCompress(args) { const { data, algorithm = 'auto' } = args; if (!data) return { error: 'Missing "data" parameter' }; const result = this.compressData(data, algorithm); this.stats.total_compressed++; this.stats.total_saved_bytes += result.originalSize - result.compressedSize; this.stats.operations++; return { compressed_base64: result.compressed.toString('base64'), algorithm: result.algorithm, original_size: result.originalSize, compressed_size: result.compressedSize, ratio: `${result.ratio.toFixed(1)}x`, saved_bytes: result.originalSize - result.compressedSize, saved_percent: `${((1 - result.compressedSize / result.originalSize) * 100).toFixed(1)}%`, ...(result.allResults ? { all_algorithms: result.allResults } : {}) }; } - index.js:309-320 (schema)The tool registration schema for 'compress', defining its input parameters and functionality description.
{ name: 'compress', description: 'Compress text/JSON/CSV data. Returns base64-encoded compressed data with compression ratio. Use algorithm="auto" to pick the best compression.', inputSchema: { type: 'object', properties: { data: { type: 'string', description: 'The data to compress (text, JSON, CSV, etc.)' }, algorithm: { type: 'string', enum: ['auto', 'gzip', 'brotli', 'deflate'], description: 'Compression algorithm. Default: auto (picks best)' } }, required: ['data'] } },