Skip to main content
Glama

compress_remote_image

Compress remote images by URL to reduce file size while maintaining quality. Save compressed images in formats like JPEG, PNG, WebP, or AVIF to specified paths.

Instructions

Compress a remote image file by giving the URL of the image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageUrlYesThe URL of the image file to compress
outputPathNoThe ABSOLUTE path to save the compressed image file
outputFormatNoThe format to save the compressed image file

Implementation Reference

  • Core handler function that compresses a remote image from URL using Tinify: sets API key, loads image, optionally converts format, determines output path, saves compressed file, fetches original size via fetch, computes and returns compression statistics.
    async function handleCompressRemoteImageTool({
      imageUrl,
      outputPath,
      outputFormat,
    }: {
      imageUrl: string;
      outputPath?: string;
      outputFormat?: SupportedImageTypes;
    }) {
      tinify.key = config.apiKey!;
      const source = tinify.fromUrl(imageUrl);
      let ext = path.extname(imageUrl).slice(1);
    
      if (outputFormat) {
        source.convert({
          type: outputFormat,
        });
        ext = outputFormat.split('/')[1];
      }
    
      let dest = outputPath;
      if (!dest) {
        const dir = path.dirname(imageUrl);
        const basename = path.basename(imageUrl, path.extname(imageUrl));
        dest = path.join(dir, `${basename}.${ext}`);
      }
    
      await source.toFile(dest);
    
      const originalSize = (await fetch(imageUrl).then((res) => res.arrayBuffer())).byteLength;
      const compressedSize = fs.statSync(dest).size;
      const compressionRatio = (originalSize - compressedSize) / originalSize;
    
      return {
        originalSize,
        compressedSize,
        compressionRatio,
      };
    }
  • Tool schema definition for 'compress_remote_image' including name, description, and inputSchema with properties imageUrl (required), outputPath, outputFormat (enum from SUPPORTED_IMAGE_TYPES).
    const COMPRESS_REMOTE_IMAGE_TOOL: Tool = {
      name: 'compress_remote_image',
      description: 'Compress a remote image file by giving the URL of the image',
      inputSchema: {
        type: 'object',
        properties: {
          imageUrl: {
            type: 'string',
            description: 'The URL of the image file to compress',
            example: 'https://example.com/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',
          },
        },
        required: ['imageUrl'],
      },
    };
  • src/tools.ts:262-279 (registration)
    MCP tool handler registration for 'compress_remote_image': extracts arguments, calls handleCompressRemoteImageTool, returns JSON stringified result as text content.
    compress_remote_image: async (request) => {
      const result = await handleCompressRemoteImageTool(
        request.params.arguments as {
          imageUrl: string;
          outputPath?: string;
          outputFormat?: SupportedImageTypes;
        },
      );
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
        metadata: {},
      };
    },
  • src/tools.ts:117-117 (registration)
    Exports the list of tools including COMPRESS_REMOTE_IMAGE_TOOL for MCP server registration.
    export const TOOLS = [COMPRESS_LOCAL_IMAGE_TOOL, COMPRESS_REMOTE_IMAGE_TOOL, RESIZE_IMAGE_TOOL];
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool compresses a remote image but doesn't mention what compression entails (e.g., quality loss, file size reduction), whether it requires internet access to fetch the image, what happens if the URL is invalid, or what the output looks like (e.g., success/failure indicators). This leaves significant gaps for a tool that performs file operations.

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 that directly states the tool's purpose without any fluff. It's appropriately sized and front-loaded, with every word contributing to understanding the core functionality.

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?

Given the tool's complexity (file processing with three parameters, no annotations, and no output schema), the description is incomplete. It doesn't explain what 'compress' means operationally, what the output entails, or potential errors. For a tool that modifies files and has no structured output documentation, more context is needed to guide effective use.

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 fully documents all three parameters (imageUrl, outputPath, outputFormat) with descriptions and examples. The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high coverage.

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 the resource 'remote image file', specifying it works on images accessible via URL. It distinguishes from the sibling 'compress_local_image' by specifying 'remote', but doesn't differentiate from 'resize_image' which is a different operation.

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?

No guidance on when to use this tool versus alternatives is provided. The description doesn't mention when to choose this over 'compress_local_image' (for local files) or 'resize_image' (for resizing rather than compression), nor does it provide any context about prerequisites or constraints.

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