Skip to main content
Glama
Ichigo3766

Image Generation MCP Server

by Ichigo3766

upscale_images

Enhance image resolution using Stable Diffusion by specifying resize mode, target dimensions, and upscaler models. Ideal for improving clarity and detail in multiple images.

Instructions

Upscale one or more images using Stable Diffusion

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imagesYesArray of image file paths to upscale
output_pathNoCustom output directory for upscaled images
resize_modeNo0 for multiplier mode (default), 1 for dimension mode
upscaler_1NoPrimary upscaler model (default: R-ESRGAN 4x+)
upscaler_2NoSecondary upscaler model (default: None)
upscaling_resizeNoUpscale multiplier (default: 4) - used when resize_mode is 0
upscaling_resize_hNoTarget height in pixels (default: 512) - used when resize_mode is 1
upscaling_resize_wNoTarget width in pixels (default: 512) - used when resize_mode is 1

Implementation Reference

  • Main handler for the 'upscale_images' tool: validates args, reads and base64-encodes input images, constructs payload for Stable Diffusion's extra-batch-images API, calls it, saves upscaled images to output directory, and returns paths.
    case 'upscale_images': {
      const args = request.params.arguments;
      if (!isUpscaleImagesArgs(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid parameters');
      }
    
      const outputDir = args.output_path ? path.normalize(args.output_path.trim()) : DEFAULT_OUTPUT_DIR;
      await this.ensureDirectoryExists(outputDir);
    
      // Read and encode all images
      const encodedImages = await Promise.all(args.images.map(async (imagePath) => {
        const data = await fs.promises.readFile(imagePath);
        return {
          data: data.toString('base64'),
          name: path.basename(imagePath)
        };
      }));
    
      // Convert resize_mode to number if present, otherwise use default
      const resizeModeNum = args.resize_mode !== undefined ? Number(args.resize_mode) : SD_RESIZE_MODE;
    
      const payload: UpscaleImagePayload = {
        resize_mode: resizeModeNum,
        show_extras_results: true,
        gfpgan_visibility: 0,
        codeformer_visibility: 0,
        codeformer_weight: 0,
        upscaling_resize: args.upscaling_resize ?? SD_UPSCALE_MULTIPLIER,
        upscaling_resize_w: args.upscaling_resize_w ?? SD_UPSCALE_WIDTH,
        upscaling_resize_h: args.upscaling_resize_h ?? SD_UPSCALE_HEIGHT,
        upscaling_crop: true,
        upscaler_1: args.upscaler_1 ?? SD_UPSCALER_1,
        upscaler_2: args.upscaler_2 ?? SD_UPSCALER_2,
        extras_upscaler_2_visibility: 0,
        upscale_first: false,
        imageList: encodedImages
      };
    
      const response = await this.axiosInstance.post('/sdapi/v1/extra-batch-images', payload);
      if (!response.data.images?.length) throw new Error('No images upscaled');
    
      const results = [];
      for (let i = 0; i < response.data.images.length; i++) {
        const imageData = response.data.images[i];
        const outputPath = path.join(outputDir, `upscaled_${path.basename(args.images[i])}`);
        
        await fs.promises.writeFile(outputPath, Buffer.from(imageData, 'base64'));
        results.push({ path: outputPath });
      }
    
      return { content: [{ type: 'text', text: JSON.stringify(results) }] };
    }
  • TypeScript interface defining the input arguments for the upscale_images tool.
    interface UpscaleImagesArgs {
      images: string[];
      resize_mode?: number;
      upscaling_resize?: number;
      upscaling_resize_w?: number;
      upscaling_resize_h?: number;
      upscaler_1?: string;
      upscaler_2?: string;
      output_path?: string;
    }
  • src/index.ts:201-244 (registration)
    Tool registration in the ListTools response, including name, description, and detailed inputSchema.
    {
      name: 'upscale_images',
      description: 'Upscale one or more images using Stable Diffusion',
      inputSchema: {
        type: 'object',
        properties: {
          images: {
            type: 'array',
            items: { type: 'string' },
            description: 'Array of image file paths to upscale'
          },
          resize_mode: {
            type: 'string',
            enum: ['0', '1'],
            description: '0 for multiplier mode (default), 1 for dimension mode'
          },
          upscaling_resize: {
            type: 'number',
            description: 'Upscale multiplier (default: 4) - used when resize_mode is 0'
          },
          upscaling_resize_w: {
            type: 'number',
            description: 'Target width in pixels (default: 512) - used when resize_mode is 1'
          },
          upscaling_resize_h: {
            type: 'number',
            description: 'Target height in pixels (default: 512) - used when resize_mode is 1'
          },
          upscaler_1: {
            type: 'string',
            description: 'Primary upscaler model (default: R-ESRGAN 4x+)'
          },
          upscaler_2: {
            type: 'string',
            description: 'Secondary upscaler model (default: None)'
          },
          output_path: {
            type: 'string',
            description: 'Custom output directory for upscaled images'
          }
        },
        required: ['images']
      }
    }
  • Runtime type guard function that validates incoming arguments match UpscaleImagesArgs structure and constraints.
    function isUpscaleImagesArgs(value: unknown): value is UpscaleImagesArgs {
      if (typeof value !== 'object' || value === null) return false;
      const v = value as Record<string, unknown>;
    
      // Validate images array
      if (!Array.isArray(v.images) || !v.images.every(img => typeof img === 'string')) {
        return false;
      }
    
      // Validate optional resize_mode as string '0' or '1'
      if (v.resize_mode !== undefined) {
        if (typeof v.resize_mode !== 'string' || !['0', '1'].includes(v.resize_mode)) return false;
      }
    
      if (v.upscaling_resize !== undefined) {
        const resize = Number(v.upscaling_resize);
        if (isNaN(resize) || resize < 1) return false;
      }
    
      if (v.upscaling_resize_w !== undefined) {
        const width = Number(v.upscaling_resize_w);
        if (isNaN(width) || width < 1) return false;
      }
    
      if (v.upscaling_resize_h !== undefined) {
        const height = Number(v.upscaling_resize_h);
        if (isNaN(height) || height < 1) return false;
      }
    
      // Validate optional string fields
      if (v.upscaler_1 !== undefined && typeof v.upscaler_1 !== 'string') return false;
      if (v.upscaler_2 !== undefined && typeof v.upscaler_2 !== 'string') return false;
      if (v.output_path !== undefined && typeof v.output_path !== 'string') return false;
    
      return true;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool 'upscales' images, implying a transformation that likely requires computational resources and may take time, but doesn't mention performance characteristics, rate limits, error handling, or what the output looks like (e.g., file paths, formats). This leaves significant gaps for an agent to understand the tool's behavior.

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 unnecessary words. It's appropriately sized and front-loaded, making it easy for an agent to quickly understand 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 complexity of an 8-parameter tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns (e.g., paths to upscaled images, success status), error conditions, or behavioral traits like processing time. For a tool that performs image transformation, more context is needed to guide proper usage.

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 input schema has 100% description coverage, providing detailed documentation for all 8 parameters. The description adds no additional parameter information beyond what's in the schema, so it meets the baseline of 3 where the schema does the heavy lifting. However, it doesn't compensate with extra context like default behaviors or usage examples.

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 ('upscale') and resource ('one or more images') with the method ('using Stable Diffusion'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this from sibling tools like 'generate_image' or 'get_sd_upscalers' which might be related to image generation or upscaler retrieval.

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. It doesn't mention sibling tools like 'generate_image' for creating new images or 'get_sd_upscalers' for listing available upscaler models, nor does it specify prerequisites such as having image files ready or when upscaling is appropriate.

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/Ichigo3766/image-gen-mcp'

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