Skip to main content
Glama

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
NameRequiredDescriptionDefault
dataYesThe data to compress (text, JSON, CSV, etc.)
algorithmNoCompression algorithm. Default: auto (picks best)

Implementation Reference

  • 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 } : {})
      };
    }
  • 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']
      }
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ShipItAndPray/mcp-compress'

If you have feedback or need assistance with the MCP directory API, please join our Discord server