Skip to main content
Glama
jbergant

Image Processor MCP Server

process_and_upload_image_from_url

Process an image from a URL by optimizing, resizing, and converting it to WebP format, then upload it to Vercel Blob storage. Ideal for efficient image management.

Instructions

Process an image from a URL (optimize, resize, convert to WebP) and upload to Vercel Blob

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
heightNoHeight to resize the image to (default: 300)
imageUrlYesURL of the image to process
newNameYesNew name for the processed image (without extension)
widthNoWidth to resize the image to (default: 550)

Implementation Reference

  • Handler logic specific to the 'process_and_upload_image_from_url' tool: destructures arguments, validates required fields, downloads the image buffer from the URL using downloadImage helper, and processes/uploads using the shared processAndUploadImageBuffer function.
    else if (toolName === "process_and_upload_image_from_url") {
      // Process image from URL
      const { imageUrl, newName, width = 550, height = 300 } = args as {
        imageUrl: string;
        newName: string;
        width?: number;
        height?: number;
      };
    
      if (!imageUrl || !newName) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "imageUrl and newName are required"
        );
      }
    
      // Download the image from the URL
      const imageBuffer = await downloadImage(imageUrl);
      
      // Process and upload the image
      result = await processAndUploadImageBuffer(imageBuffer, newName, width, height);
    }
  • Tool schema definition including name, description, and input schema with properties for imageUrl (required), newName (required), width, and height.
    {
      name: "process_and_upload_image_from_url",
      description: "Process an image from a URL (optimize, resize, convert to WebP) and upload to Vercel Blob",
      inputSchema: {
        type: "object",
        properties: {
          imageUrl: {
            type: "string",
            description: "URL of the image to process"
          },
          newName: {
            type: "string",
            description: "New name for the processed image (without extension)"
          },
          width: {
            type: "number",
            description: "Width to resize the image to (default: 550)"
          },
          height: {
            type: "number",
            description: "Height to resize the image to (default: 300)"
          }
        },
        required: ["imageUrl", "newName"]
      }
    }
  • Core helper function that takes an image Buffer, resizes and optimizes to PNG (_small.png), converts to WebP, saves to temp files, checks for existing blobs, uploads if new to Vercel Blob, and returns URLs and paths.
    async function processAndUploadImageBuffer(
      imageBuffer: Buffer,
      newName: string,
      width: number = 550,
      height: number = 300
    ): Promise<any> {
      // Process results
      const results = {
        png: { localPath: "", blobUrl: "" },
        webp: { localPath: "", blobUrl: "" }
      };
    
      // Create temporary directory for processed images
      const tempDir = await createTempDir();
    
      // Process PNG version
      const optimizedBuffer = await sharp(imageBuffer)
        .resize(width, height)
        .png({
          quality: 80,
          effort: 6
        })
        .toBuffer();
      
      const smallFileName = `${newName}_small.png`;
      const smallFilePath = path.join(tempDir, smallFileName);
      await fs.writeFile(smallFilePath, optimizedBuffer);
      results.png.localPath = smallFilePath;
    
      // Check if PNG already exists in Vercel Blob storage
      let pngUrl = "";
      try {
        const existingUrl = await list({ prefix: smallFileName });
        if (existingUrl.blobs.length > 0) {
          pngUrl = existingUrl.blobs[0].url;
        } else {
          // Upload if not found
          const { url } = await put(smallFileName, optimizedBuffer, {
            access: "public", 
            contentType: "image/png"
          });
          pngUrl = url;
        }
      } catch (error) {
        console.error(`Failed to check/upload PNG blob: ${error}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to upload PNG to Vercel Blob: ${error}`
        );
      }
      results.png.blobUrl = pngUrl;
    
      // Process WebP version
      const optimizedBufferWebp = await sharp(imageBuffer)
        .webp({ 
          quality: 80,
          effort: 6
        })
        .toBuffer();
      
      const webpFileName = `${newName}.webp`;
      const webpFilePath = path.join(tempDir, webpFileName);
      await fs.writeFile(webpFilePath, optimizedBufferWebp);
      results.webp.localPath = webpFilePath;
    
      // Check if WebP already exists in Vercel Blob storage
      let webpUrl = "";
      try {
        const existingUrlWebp = await list({ prefix: webpFileName });
        if (existingUrlWebp.blobs.length > 0) {
          webpUrl = existingUrlWebp.blobs[0].url;
        } else {
          // Upload if not found
          const { url } = await put(webpFileName, optimizedBufferWebp, {
            access: "public", 
            contentType: "image/webp"
          });
          webpUrl = url;
        }
      } catch (error) {
        console.error(`Failed to check/upload WebP blob: ${error}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to upload WebP to Vercel Blob: ${error}`
        );
      }
      results.webp.blobUrl = webpUrl;
    
      return {
        success: true,
        message: `Successfully processed and uploaded image: ${newName}`,
        results: {
          png: {
            fileName: smallFileName,
            localPath: results.png.localPath,
            blobUrl: results.png.blobUrl
          },
          webp: {
            fileName: webpFileName,
            localPath: results.webp.localPath,
            blobUrl: results.webp.blobUrl
          }
        }
      };
    }
  • Helper function to download an image from a given URL using axios and return it as a Buffer.
    async function downloadImage(url: string): Promise<Buffer> {
      try {
        const response = await axios.get(url, {
          responseType: 'arraybuffer'
        });
        return Buffer.from(response.data, 'binary');
      } catch (error) {
        console.error(`Failed to download image from URL: ${url}`, error);
        throw new Error(`Failed to download image from URL: ${url}`);
      }
    }
  • src/index.ts:88-145 (registration)
    Registration of available tools via ListToolsRequestSchema handler, including this tool in the tools array.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "process_and_upload_image",
            description: "Process a local image file (optimize, resize, convert to WebP) and upload to Vercel Blob",
            inputSchema: {
              type: "object",
              properties: {
                imagePath: {
                  type: "string",
                  description: "Path to the image file to process"
                },
                newName: {
                  type: "string",
                  description: "New name for the processed image (without extension)"
                },
                width: {
                  type: "number",
                  description: "Width to resize the image to (default: 550)"
                },
                height: {
                  type: "number",
                  description: "Height to resize the image to (default: 300)"
                }
              },
              required: ["imagePath", "newName"]
            }
          },
          {
            name: "process_and_upload_image_from_url",
            description: "Process an image from a URL (optimize, resize, convert to WebP) and upload to Vercel Blob",
            inputSchema: {
              type: "object",
              properties: {
                imageUrl: {
                  type: "string",
                  description: "URL of the image to process"
                },
                newName: {
                  type: "string",
                  description: "New name for the processed image (without extension)"
                },
                width: {
                  type: "number",
                  description: "Width to resize the image to (default: 550)"
                },
                height: {
                  type: "number",
                  description: "Height to resize the image to (default: 300)"
                }
              },
              required: ["imageUrl", "newName"]
            }
          }
        ]
      };
    });
Behavior3/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. It discloses key behavioral traits: the tool processes (optimizes, resizes, converts to WebP) and uploads to Vercel Blob. However, it lacks details on permissions, rate limits, error handling, or what happens if upload fails, which are important for a mutation tool.

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 front-loads the core purpose. Every word earns its place by specifying the action, source, processing steps, and destination without any redundancy or fluff.

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

Completeness3/5

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

Given the tool's complexity (image processing and upload), lack of annotations, and no output schema, the description is minimally adequate. It covers the what and where but misses details on behavioral aspects like success/failure outcomes, which would enhance completeness for a mutation tool.

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?

The schema description coverage is 100%, so the schema already documents all parameters. The description does not add any additional meaning or context beyond what the schema provides, such as explaining the optimization process or WebP conversion specifics. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the specific action: 'Process an image from a URL (optimize, resize, convert to WebP) and upload to Vercel Blob'. It uses precise verbs ('process', 'upload'), specifies the resource ('image'), and distinguishes from its sibling 'process_and_upload_image' by explicitly mentioning 'from a URL'.

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

Usage Guidelines4/5

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

The description implies usage context by specifying 'from a URL', which suggests this tool is for remote images rather than local files. However, it does not explicitly state when to use this versus the sibling tool 'process_and_upload_image' or provide any exclusion criteria, leaving some ambiguity.

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

Related 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/jbergant/mcp_image_processor_to_vercel_blob'

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