Skip to main content
Glama

compress

Compress files or directories into ZIP archives with configurable compression levels, password protection, and encryption options.

Instructions

Compress local files or directories into a ZIP file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesFile path(s) or directory to compress
outputYesOutput ZIP file path
optionsNo

Implementation Reference

  • The implementation of the 'compress' tool handler which takes file/directory paths and creates a ZIP file.
    case "compress": {
      const input = args.input as string | string[];
      const output = args.output as string;
      const options = (args.options as any) || {};
    
      if (fs.existsSync(output) && !options.overwrite) {
        throw new Error(`Output file already exists: ${output}`);
      }
    
      const zip = new AdmZip();
    
      const inputs = Array.isArray(input) ? input : [input];
    
      for (const inputPath of inputs) {
        if (!fs.existsSync(inputPath)) {
          throw new Error(`Input path does not exist: ${inputPath}`);
        }
    
        const stats = fs.statSync(inputPath);
    
        if (stats.isDirectory()) {
          zip.addLocalFolder(inputPath, path.basename(inputPath));
        } else {
          zip.addLocalFile(inputPath);
        }
      }
    
      if (options.comment) {
        zip.addZipComment(options.comment);
      }
    
      zip.writeZip(output);
    
      const outputStats = fs.statSync(output);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                success: true,
                output: output,
                size: outputStats.size,
                files: zip.getEntries().length,
              },
              null,
              2,
            ),
          },
        ],
      };
    }
  • The schema definition for the 'compress' tool.
    {
      name: "compress",
      description: "Compress local files or directories into a ZIP file",
      inputSchema: {
        type: "object",
        properties: {
          input: {
            anyOf: [
              { type: "string" },
              { type: "array", items: { type: "string" } },
            ],
            description: "File path(s) or directory to compress",
          },
          output: {
            type: "string",
            description: "Output ZIP file path",
          },
          options: {
            type: "object",
            properties: {
              overwrite: {
                type: "boolean",
                description: "Overwrite if output file exists",
              },
              level: {
                type: "number",
                description: "Compression level (0-9)",
                minimum: 0,
                maximum: 9,
              },
              password: {
                type: "string",
                description: "Password to encrypt ZIP file",
              },
              comment: {
                type: "string",
                description: "ZIP file comment",
              },
              encryptionStrength: {
                type: "number",
                enum: [1, 2, 3],
                description:
                  "Encryption strength (1=AES-128, 2=AES-192, 3=AES-256)",
              },
            },
          },
        },
        required: ["input", "output"],
      },
    },
Install Server

Other Tools

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/loscolmebrothers/zip-mcp'

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