Skip to main content
Glama
Ichigo3766

Image Generation MCP Server

by Ichigo3766

generate_image

Create custom images using text prompts with Stable Diffusion. Customize dimensions, sampling steps, and other parameters to generate tailored visuals for your needs.

Instructions

Generate an image using Stable Diffusion

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
batch_sizeNoNumber of images to generate (default: 1)
cfg_scaleNoCFG scale (default: 1)
distilled_cfg_scaleNoDistilled CFG scale (default: 3.5)
heightNoImage height (default: 1024)
negative_promptNoThings to exclude from the image
output_pathNoCustom output path for the generated image
promptYesThe prompt describing the desired image
restore_facesNoEnable face restoration
sampler_nameNoSampling algorithm (default: Euler)Euler
scheduler_nameNoScheduler algorithm (default: Simple)Simple
seedNoRandom seed (-1 for random)
stepsNoNumber of sampling steps (default: 4)
tilingNoGenerate tileable images
widthNoImage width (default: 1024)

Implementation Reference

  • Main handler for 'generate_image' tool: validates input, calls Stable Diffusion txt2img API, decodes and saves images with metadata, returns list of generated image paths.
    case 'generate_image': {
      const args = request.params.arguments;
      if (!isGenerateImageArgs(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);
    
      const payload: SDAPIPayload = {
        prompt: args.prompt,
        negative_prompt: args.negative_prompt || '',
        steps: args.steps || 4,
        width: args.width || 1024,
        height: args.height || 1024,
        cfg_scale: args.cfg_scale || 1,
        sampler_name: args.sampler_name || 'Euler',
        seed: args.seed ?? -1,
        n_iter: args.batch_size || 1,
        distilled_cfg_scale: args.distilled_cfg_scale || 3.5,
        scheduler: args.scheduler_name || 'Simple',
        tiling: !!args.tiling,
        restore_faces: !!args.restore_faces
      };
    
      const response = await this.axiosInstance.post('/sdapi/v1/txt2img', payload);
      if (!response.data.images?.length) throw new Error('No images generated');
    
      const results = [];
      for (const imageData of response.data.images) {
        const base64Data = imageData.includes(',') ? imageData.split(',')[1] : imageData;
        const pngInfoResponse = await this.axiosInstance.post('/sdapi/v1/png-info', { image: `data:image/png;base64,${imageData}` });
        
        const outputPath = path.join(outputDir, `sd_${randomUUID()}.png`);
        const imageBuffer = Buffer.from(base64Data, 'base64');
        
        await sharp(imageBuffer)
          .withMetadata({ exif: { IFD0: { ImageDescription: pngInfoResponse.data.info } } })
          .toFile(outputPath);
    
        results.push({ path: outputPath, parameters: pngInfoResponse.data.info });
      }
    
      return { content: [{ type: 'text', text: JSON.stringify(results) }] };
    }
  • TypeScript interface defining the input arguments for the generate_image tool.
    interface GenerateImageArgs {
      prompt: string;
      negative_prompt?: string;
      steps?: number;
      width?: number;
      height?: number;
      cfg_scale?: number;
      sampler_name?: string;
      scheduler_name?: string;
      seed?: number;
      batch_size?: number;
      restore_faces?: boolean;
      tiling?: boolean;
      output_path?: string;
      distilled_cfg_scale?: number;
    }
  • src/index.ts:148-171 (registration)
    Tool registration in the MCP server's tools list, including name, description, and detailed JSON schema for input validation.
    {
      name: 'generate_image',
      description: 'Generate an image using Stable Diffusion',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: { type: 'string', description: 'The prompt describing the desired image' },
          negative_prompt: { type: 'string', description: 'Things to exclude from the image' },
          steps: { type: 'number', description: 'Number of sampling steps (default: 4)', minimum: 1, maximum: 150 },
          width: { type: 'number', description: 'Image width (default: 1024)', minimum: 512, maximum: 2048 },
          height: { type: 'number', description: 'Image height (default: 1024)', minimum: 512, maximum: 2048 },
          cfg_scale: { type: 'number', description: 'CFG scale (default: 1)', minimum: 1, maximum: 30 },
          sampler_name: { type: 'string', description: 'Sampling algorithm (default: Euler)', default: 'Euler' },
          scheduler_name: { type: 'string', description: 'Scheduler algorithm (default: Simple)', default: 'Simple' },
          seed: { type: 'number', description: 'Random seed (-1 for random)', minimum: -1 },
          batch_size: { type: 'number', description: 'Number of images to generate (default: 1)', minimum: 1, maximum: 4 },
          restore_faces: { type: 'boolean', description: 'Enable face restoration' },
          tiling: { type: 'boolean', description: 'Generate tileable images' },
          distilled_cfg_scale: { type: 'number', description: 'Distilled CFG scale (default: 3.5)', minimum: 1, maximum: 30 },
          output_path: { type: 'string', description: 'Custom output path for the generated image' }
        },
        required: ['prompt']
      }
    },
  • Runtime type guard function to validate and cast input arguments to GenerateImageArgs type before handling the tool call.
    function isGenerateImageArgs(value: unknown): value is GenerateImageArgs {
      if (typeof value !== 'object' || value === null) return false;
      const v = value as Record<string, unknown>;
      
      // Validate string fields
      if (typeof v.prompt !== 'string') return false;
      if (v.negative_prompt !== undefined && typeof v.negative_prompt !== 'string') return false;
      
      // Convert and validate numeric fields
      if (v.steps !== undefined) {
        const steps = Number(v.steps);
        if (isNaN(steps) || steps < 1 || steps > 150) return false;
        v.steps = steps;
      }
      
      if (v.batch_size !== undefined) {
        const batchSize = Number(v.batch_size);
        if (isNaN(batchSize) || batchSize < 1 || batchSize > 4) return false;
        v.batch_size = batchSize;
      }
      
      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 but only states the basic function. It doesn't cover critical aspects like whether this is a long-running operation, rate limits, authentication needs, output format (e.g., file paths or URLs), or error handling, leaving significant gaps for an AI agent.

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 wasted words. It's appropriately sized and front-loaded, making it easy to parse quickly for an AI agent.

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 a 14-parameter image generation tool with no annotations and no output schema, the description is insufficient. It lacks details on behavioral traits, output handling, and usage context, failing to provide the completeness needed for effective tool invocation despite the rich input schema.

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 14 parameters, including defaults and constraints. The description adds no additional parameter information beyond what the schema already covers, so it meets the baseline for high schema coverage without compensating value.

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 ('Generate') and resource ('an image') with the specific method ('using Stable Diffusion'), making the purpose immediately understandable. It doesn't differentiate from sibling tools like 'upscale_images' or 'set_sd_model', which would require explicit comparison.

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 like 'upscale_images' for enhancing existing images or 'set_sd_model' for configuring models. There's no mention of prerequisites, such as needing a model loaded via 'set_sd_model', leaving usage context implied at best.

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