Skip to main content
Glama
jbergant

Image Processor MCP Server

process_and_upload_image

Optimize, resize, and convert local image files to WebP format, then upload them to Vercel Blob storage for efficient cloud integration.

Instructions

Process a local image file (optimize, resize, convert to WebP) and upload to Vercel Blob

Input Schema

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

Implementation Reference

  • Specific handler logic for 'process_and_upload_image' tool: validates inputs, reads local image file into buffer, and invokes the core processing function.
    if (toolName === "process_and_upload_image") {
      // Process local image file
      const { imagePath, newName, width = 550, height = 300 } = args as {
        imagePath: string;
        newName: string;
        width?: number;
        height?: number;
      };
    
      if (!imagePath || !newName) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "imagePath and newName are required"
        );
      }
    
      if (!fs.existsSync(imagePath)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Image file not found: ${imagePath}`
        );
      }
    
      // Read the image file
      const imageBuffer = await fs.readFile(imagePath);
      
      // Process and upload the image
      result = await processAndUploadImageBuffer(imageBuffer, newName, width, height);
    } 
  • Core helper function that takes an image buffer, resizes and optimizes PNG version, optimizes WebP version, saves to temp files, and uploads both to Vercel Blob (checking for existence first). Returns URLs.
    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
          }
        }
      };
    }
  • Input schema definition for the 'process_and_upload_image' tool, including properties and requirements.
    {
      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"]
      }
    },
  • src/index.ts:88-145 (registration)
    Registration of the tool via the ListToolsRequestSchema handler, which returns the tool list including 'process_and_upload_image'.
    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"]
            }
          }
        ]
      };
    });
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. It mentions processing (optimize, resize, convert) and uploading, but lacks details on behavioral traits like required permissions, rate limits, error handling, or what happens if processing fails. For a tool that modifies and uploads files with no 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 that front-loads key information (process local image, upload to Vercel Blob) and includes essential details (optimize, resize, convert to WebP). Every part earns its place with no wasted words.

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 (processing and uploading images) and lack of annotations and output schema, the description is moderately complete. It covers the core purpose and distinguishes from siblings, but lacks details on behavioral aspects and output, which are important for a tool with mutation and external integration.

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 parameters. The description adds no specific parameter semantics beyond what the schema provides, such as explaining interactions between parameters (e.g., how width/height affect resizing). Baseline 3 is appropriate when the schema handles parameter documentation.

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 verb ('process and upload') and resource ('local image file'), and distinguishes from the sibling tool 'process_and_upload_image_from_url' by specifying the source as local rather than URL-based. It explicitly lists the processing operations: optimize, resize, convert to WebP, and the destination: Vercel Blob.

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 provides clear context for when to use this tool (for local image files) and implies an alternative (the sibling tool for URL-based images). However, it does not explicitly state when NOT to use this tool or mention other potential alternatives beyond the sibling, such as direct upload without processing.

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