Skip to main content
Glama
Garoth
by Garoth

create_variation

Generate multiple visual variations of an existing image using DALL-E, allowing creative exploration and alternative versions of original artwork.

Instructions

Create variations of an existing image using DALL-E

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imagePathYesPath to the image to create variations of
modelNoDALL-E model to use (currently only dall-e-2 supports variations)
sizeNoSize of the generated image
nNoNumber of variations to generate (1-10)
saveDirNoDirectory to save the variation images
fileNameNoBase filename for the variation images (without extension)

Implementation Reference

  • MCP tool handler for 'create_variation': resolves image path, invokes DalleService.createVariation, formats success/error response with saved variation paths.
    handler: async (args: VariationArgs): Promise<ToolResponse> => {
      // Resolve relative path to absolute path
      const imagePath = path.isAbsolute(args.imagePath) 
        ? args.imagePath 
        : path.resolve(process.cwd(), args.imagePath);
    
      const result = await dalleService.createVariation(imagePath, {
        model: args.model,
        size: args.size,
        n: args.n,
        saveDir: args.saveDir,
        fileName: args.fileName
      });
    
      if (!result.success) {
        return {
          content: [{
            type: "text",
            text: `Error creating image variations: ${result.error}`
          }]
        };
      }
    
      const imagePaths = result.imagePaths || [];
      const imageCount = imagePaths.length;
      const model = result.model || 'dall-e-2';
    
      let responseText = `Successfully created ${imageCount} variation${imageCount !== 1 ? 's' : ''} using ${model}.\n\n`;
      responseText += `Original image: ${imagePath}\n\n`;
      responseText += `Variation${imageCount !== 1 ? 's' : ''} saved to:\n`;
      
      imagePaths.forEach(imagePath => {
        responseText += `- ${imagePath}\n`;
      });
    
      return {
        content: [{
          type: "text",
          text: responseText
        }]
      };
    }
  • Core implementation in DalleService: calls OpenAI API /images/variations, saves generated variation images to disk, returns ImageGenerationResult.
    async createVariation(
      imagePath: string,
      options: {
        model?: string;
        size?: string;
        n?: number;
        saveDir?: string;
        fileName?: string;
      } = {}
    ): Promise<ImageGenerationResult> {
      try {
        // Set default options
        const model = options.model || 'dall-e-2'; // DALL-E 3 doesn't support variations yet
        const size = options.size || '1024x1024';
        const n = options.n || 1;
        const saveDir = options.saveDir || this.config.defaultSaveDir || process.cwd();
        const fileName = options.fileName || `dalle-variation-${Date.now()}`;
    
        // Ensure save directory exists
        await fs.ensureDir(saveDir);
    
        // Check if image exists
        if (!await fs.pathExists(imagePath)) {
          return {
            success: false,
            error: `Image file not found: ${imagePath}`
          };
        }
    
        // Create form data
        const formData = new FormData();
        formData.append('n', n.toString());
        formData.append('size', size);
        formData.append('response_format', 'b64_json');
    
        // Read image file and append to form
        const imageBuffer = await fs.readFile(imagePath);
        formData.append('image', imageBuffer, {
          filename: path.basename(imagePath),
          contentType: 'image/png'
        });
    
        // Make request to OpenAI API
        const response = await axios.post(
          `${this.baseUrl}/images/variations`,
          formData,
          {
            headers: {
              'Content-Type': 'multipart/form-data',
              'Authorization': `Bearer ${this.config.apiKey}`
            }
          }
        );
    
        // Process response
        const data = response.data;
        const imagePaths: string[] = [];
    
        // Save each image
        for (let i = 0; i < data.data.length; i++) {
          const item = data.data[i];
          const resultBuffer = Buffer.from(item.b64_json, 'base64');
          let resultPath = path.join(saveDir, `${fileName}${n > 1 ? `-${i + 1}` : ''}.png`);
          
          // Ensure the path is absolute
          if (!path.isAbsolute(resultPath)) {
            resultPath = path.resolve(process.cwd(), resultPath);
          }
          
          await fs.writeFile(resultPath, resultBuffer);
          imagePaths.push(resultPath);
        }
    
        return {
          success: true,
          imagePaths,
          model
        };
      } catch (error) {
        console.log("DALL-E API Error:", error);
        
        let errorMessage = 'Failed to create image variation';
        
        if (axios.isAxiosError(error) && error.response?.data?.error) {
          errorMessage = `DALL-E API Error: ${error.response.data.error.message}`;
        } else if (error instanceof Error) {
          errorMessage = error.message;
        }
        
        return {
          success: false,
          error: errorMessage
        };
      }
    }
  • Input schema for 'create_variation' tool defining parameters, types, enums, and required fields.
    inputSchema: {
      type: "object",
      properties: {
        imagePath: {
          type: "string",
          description: "Path to the image to create variations of"
        },
        model: {
          type: "string",
          description: "DALL-E model to use (currently only dall-e-2 supports variations)",
          enum: ["dall-e-2"]
        },
        size: {
          type: "string",
          description: "Size of the generated image",
          enum: ["256x256", "512x512", "1024x1024"]
        },
        n: {
          type: "number",
          description: "Number of variations to generate (1-10)",
          minimum: 1,
          maximum: 10
        },
        saveDir: {
          type: "string",
          description: "Directory to save the variation images"
        },
        fileName: {
          type: "string",
          description: "Base filename for the variation images (without extension)"
        }
      },
      required: ["imagePath"]
    },
  • src/index.ts:25-32 (registration)
    MCP server capabilities registration declaring 'create_variation' tool availability.
        tools: {
          generate_image: true,
          edit_image: true,
          create_variation: true,
          validate_key: true
        },
      },
    }
  • src/index.ts:88-90 (registration)
    Dispatcher in main tool call handler that routes 'create_variation' calls to the specific tool handler.
    case 'create_variation':
      response = await (tool as Tool<VariationArgs>).handler(args as unknown as VariationArgs);
      break;
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. While 'create variations' implies a generative operation, the description doesn't mention important behavioral aspects like whether this is a read-only operation, what permissions are needed, rate limits, cost implications, or what happens to the original image. For a tool with 6 parameters and 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 states the core purpose without any wasted words. It's appropriately sized for the tool's complexity and gets straight to the point with no unnecessary elaboration.

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?

For a generative AI tool with 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (e.g., image paths, URLs, error handling), doesn't mention DALL-E API constraints or costs, and provides no guidance on usage context. The 100% schema coverage helps with parameters, but other critical contextual information is missing.

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 description mentions 'variations of an existing image' which provides context for the 'imagePath' parameter, but doesn't add meaningful semantic information beyond what's already in the schema (which has 100% coverage). The schema descriptions comprehensively document each parameter's purpose, constraints, and enums, so the description adds minimal value here.

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 ('create variations') and resource ('existing image using DALL-E'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'edit_image' or 'generate_image', but the focus on variations of existing images provides some implicit distinction.

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 'edit_image' or 'generate_image'. There's no mention of prerequisites, constraints, or typical use cases, leaving the agent with no contextual usage information beyond the basic purpose.

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

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/Garoth/dalle-mcp'

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