Skip to main content
Glama

compress_local_image

Compress local image files to reduce file size while maintaining quality. Specify input and output paths, choose formats like JPEG, PNG, or WebP, and optionally preserve metadata.

Instructions

Compress a local image file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imagePathYesThe ABSOLUTE path to the image file to compress
outputPathNoThe ABSOLUTE path to save the compressed image file
outputFormatNoThe format to save the compressed image file
preserveMetadataNoThe metadata to preserve in the image file

Implementation Reference

  • Defines the tool schema including name, description, and inputSchema with properties for imagePath (required), outputPath, outputFormat, and preserveMetadata.
    const COMPRESS_LOCAL_IMAGE_TOOL: Tool = {
      name: 'compress_local_image',
      description: 'Compress a local image file',
      inputSchema: {
        type: 'object',
        properties: {
          imagePath: {
            type: 'string',
            description: 'The ABSOLUTE path to the image file to compress',
            example: '/Users/user/Downloads/image.jpg',
          },
          outputPath: {
            type: 'string',
            description: 'The ABSOLUTE path to save the compressed image file',
            example: '/Users/user/Downloads/image_compressed.jpg',
          },
          outputFormat: {
            type: 'string',
            description: 'The format to save the compressed image file',
            enum: SUPPORTED_IMAGE_TYPES,
            example: 'image/jpeg',
          },
          preserveMetadata: {
            type: 'array',
            description: 'The metadata to preserve in the image file',
            items: {
              type: 'string',
              enum: ['copyright', 'creation', 'location'],
            },
          },
        },
        required: ['imagePath'],
      },
    };
  • Core handler function that performs the image compression using the tinify library. Handles metadata preservation, format conversion, automatic output path generation with '_compressed' suffix, saves the file, and returns compression statistics (originalSize, compressedSize, compressionRatio).
    async function handleCompressLocalImageTool({
      imagePath,
      outputPath,
      outputFormat,
      preserveMetadata,
    }: {
      imagePath: string;
      outputPath?: string;
      outputFormat?: SupportedImageTypes;
      preserveMetadata?: string[];
    }) {
      const originalSize = fs.statSync(imagePath).size;
      tinify.key = config.apiKey!;
      let source = tinify.fromFile(imagePath);
    
      if (preserveMetadata?.length) {
        source = source.preserve(...preserveMetadata);
      }
    
      let ext = path.extname(imagePath).slice(1);
    
      if (outputFormat) {
        source.convert({
          type: outputFormat,
        });
        ext = outputFormat.split('/')[1];
      }
    
      let dest = outputPath;
      if (!dest) {
        const dir = path.dirname(imagePath);
        const basename = path.basename(imagePath, path.extname(imagePath));
        dest = path.join(dir, `${basename}.${ext}`);
      }
    
      // add _compressed to the filename
      const destDir = path.dirname(dest);
      const destBasename = path.basename(dest, path.extname(dest));
      if (!destBasename.endsWith('_compressed')) {
        dest = path.join(destDir, `${destBasename}_compressed.${ext}`);
      }
    
      await source.toFile(dest);
    
      const compressedSize = fs.statSync(dest).size;
      const compressionRatio = (originalSize - compressedSize) / originalSize;
    
      return {
        originalSize,
        compressedSize,
        compressionRatio,
      };
    }
  • src/tools.ts:117-117 (registration)
    Registers the compress_local_image tool schema (via COMPRESS_LOCAL_IMAGE_TOOL) in the exported TOOLS array used for MCP tool discovery.
    export const TOOLS = [COMPRESS_LOCAL_IMAGE_TOOL, COMPRESS_REMOTE_IMAGE_TOOL, RESIZE_IMAGE_TOOL];
  • src/tools.ts:244-261 (registration)
    Registers the handler for 'compress_local_image' in the TOOL_HANDLERS map, wrapping the core handler and formatting the MCP response with JSON-stringified results.
    compress_local_image: async (request) => {
      const result = await handleCompressLocalImageTool(
        request.params.arguments as {
          imagePath: string;
          outputPath?: string;
          outputFormat?: SupportedImageTypes;
        },
      );
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
        metadata: {},
      };
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits like whether the operation is destructive (overwrites files), requires specific permissions, has performance implications, or what happens on failure. This is inadequate for a mutation tool with zero annotation coverage.

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 perfectly front-loaded with the core action and resource, making it immediately scannable and understandable 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 4 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'compress' means operationally (e.g., quality reduction, format conversion), what the output looks like, or error conditions. The agent lacks critical context for proper tool invocation.

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 parameters are fully documented in the schema. The description adds no additional parameter semantics beyond what's already in the structured data, maintaining the baseline score of 3 where 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 action ('compress') and resource ('a local image file'), making the purpose immediately understandable. It distinguishes from 'compress_remote_image' by specifying 'local' but doesn't explicitly differentiate from 'resize_image' which might also involve compression.

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 like 'compress_remote_image' or 'resize_image'. There's no mention of prerequisites, use cases, or when not to use this tool, leaving the agent without contextual decision-making support.

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/aiyogg/tinypng-mcp-server'

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