Skip to main content
Glama

compress_image

Reduce image file size while maintaining quality using configurable compression settings for JPEG, PNG, WebP, and AVIF formats.

Instructions

Compress an image with quality settings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to input image
outputPathYesPath to save compressed image
qualityNoCompression quality (1-100)
progressiveNoUse progressive encoding (for JPEG)

Implementation Reference

  • Handler for the 'compress_image' tool. Extracts arguments, creates output directory, detects image format using Sharp metadata, applies format-specific compression (JPEG, PNG, WebP, AVIF) with specified quality and progressive option, saves the compressed image, calculates and reports size reduction percentage.
    case 'compress_image': {
      const { inputPath, outputPath, quality = 80, progressive = true } = args;
      
      await fs.mkdir(path.dirname(outputPath), { recursive: true });
      
      const metadata = await sharp(inputPath).metadata();
      let pipeline = sharp(inputPath);
      
      // Apply compression based on format
      if (metadata.format === 'jpeg') {
        pipeline = pipeline.jpeg({ quality, progressive });
      } else if (metadata.format === 'png') {
        pipeline = pipeline.png({ quality });
      } else if (metadata.format === 'webp') {
        pipeline = pipeline.webp({ quality });
      } else if (metadata.format === 'avif') {
        pipeline = pipeline.avif({ quality });
      }
      
      await pipeline.toFile(outputPath);
      
      const originalSize = (await fs.stat(inputPath)).size;
      const compressedSize = (await fs.stat(outputPath)).size;
      const savings = ((originalSize - compressedSize) / originalSize * 100).toFixed(1);
      
      return {
        content: [
          {
            type: 'text',
            text: `Image compressed successfully. Saved to: ${outputPath}\nSize reduction: ${savings}% (${originalSize} → ${compressedSize} bytes)`
          }
        ]
      };
    }
  • src/index.ts:93-116 (registration)
    Registration of the 'compress_image' tool in the listTools handler, including name, description, and input schema for validation.
    {
      name: 'compress_image',
      description: 'Compress an image with quality settings',
      inputSchema: {
        type: 'object',
        properties: {
          inputPath: { type: 'string', description: 'Path to input image' },
          outputPath: { type: 'string', description: 'Path to save compressed image' },
          quality: {
            type: 'number',
            minimum: 1,
            maximum: 100,
            description: 'Compression quality (1-100)',
            default: 80
          },
          progressive: {
            type: 'boolean',
            description: 'Use progressive encoding (for JPEG)',
            default: true
          }
        },
        required: ['inputPath', 'outputPath']
      }
    },
  • Input schema definition for the compress_image tool, specifying parameters like inputPath, outputPath, quality, and progressive.
    inputSchema: {
      type: 'object',
      properties: {
        inputPath: { type: 'string', description: 'Path to input image' },
        outputPath: { type: 'string', description: 'Path to save compressed image' },
        quality: {
          type: 'number',
          minimum: 1,
          maximum: 100,
          description: 'Compression quality (1-100)',
          default: 80
        },
        progressive: {
          type: 'boolean',
          description: 'Use progressive encoding (for JPEG)',
          default: true
        }
      },
      required: ['inputPath', 'outputPath']
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Compress' implies a mutation operation that likely reduces file size, but the description doesn't state whether this is lossy/lossless, what formats are supported, whether the original file is preserved, or what happens on failure. For a mutation tool with zero annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a tool with good schema documentation and gets straight to the point without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is inadequate. It doesn't explain what the tool returns, what side effects occur, what error conditions might arise, or how it differs from sibling tools. The 100% schema coverage helps with parameters, but overall completeness is poor for a tool that modifies files.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all four parameters thoroughly. The description adds minimal value beyond the schema - it mentions 'quality settings' which aligns with the 'quality' parameter but doesn't provide additional context about the other parameters (inputPath, outputPath, progressive). Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Compress') and resource ('an image') with the specific operation ('with quality settings'). It distinguishes from siblings like resize_image or convert_format by focusing on compression rather than dimension/format changes. However, it doesn't explicitly differentiate from all siblings (e.g., batch_resize might also affect file size).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when compression is appropriate (e.g., for reducing file size), when not to use it (e.g., for lossless operations), or which sibling tools might be alternatives for related tasks like format conversion or resizing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/flowy11/imagician'

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