Skip to main content
Glama

compress_remote_image

Compress remote images by providing their URL to reduce file size while maintaining quality. Supports JPEG, PNG, WebP, and AVIF formats with customizable output 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
outputFormatNoThe format to save the compressed image file
outputPathNoThe ABSOLUTE path to save the compressed image file

Implementation Reference

  • MCP tool handler for 'compress_remote_image' that extracts arguments from request, calls the core compression function, and returns formatted text content with results.
    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: {}, }; },
  • Core implementation of remote image compression using Tinify API: loads image from URL, optionally converts format, determines output path, compresses and saves file, calculates original vs compressed sizes and ratio.
    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 definition including name, description, and input schema for 'compress_remote_image'.
    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:117-117 (registration)
    Exports the array 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];

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