Skip to main content
Glama
Garoth
by Garoth

generate_image

Create images from text descriptions using DALL-E AI models, with options for size, quality, style, and quantity.

Instructions

Generate an image using DALL-E based on a text prompt

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText description of the desired image
modelNoDALL-E model to use (dall-e-2 or dall-e-3)
sizeNoSize of the generated image
qualityNoQuality of the generated image (dall-e-3 only)
styleNoStyle of the generated image (dall-e-3 only)
nNoNumber of images to generate (1-10)
saveDirNoDirectory to save the generated images
fileNameNoBase filename for the generated images (without extension)

Implementation Reference

  • The handler function that executes the 'generate_image' tool logic, calling DalleService and formatting the response with saved image paths.
    handler: async (args: GenerateImageArgs): Promise<ToolResponse> => {
      const result = await dalleService.generateImage(args.prompt, {
        model: args.model,
        size: args.size,
        quality: args.quality,
        style: args.style,
        n: args.n,
        saveDir: args.saveDir,
        fileName: args.fileName
      });
    
      if (!result.success) {
        return {
          content: [{
            type: "text",
            text: `Error generating image: ${result.error}`
          }]
        };
      }
    
      const imagePaths = result.imagePaths || [];
      const imageCount = imagePaths.length;
      const model = result.model || 'dall-e-3';
    
      let responseText = `Successfully generated ${imageCount} image${imageCount !== 1 ? 's' : ''} using ${model}.\n\n`;
      responseText += `Prompt: "${result.prompt}"\n\n`;
      responseText += `Image${imageCount !== 1 ? 's' : ''} saved to:\n`;
      
      imagePaths.forEach(imagePath => {
        responseText += `- ${imagePath}\n`;
      });
    
      return {
        content: [{
          type: "text",
          text: responseText
        }]
      };
    }
  • Core helper method in DalleService that performs the OpenAI DALL-E API call for image generation, handles base64 decoding, saves images to disk, and returns result.
    async generateImage(
      prompt: string,
      options: {
        model?: string;
        size?: string;
        quality?: string;
        style?: string;
        n?: number;
        saveDir?: string;
        fileName?: string;
      } = {}
    ): Promise<ImageGenerationResult> {
      try {
        // Set default options
        const model = options.model || 'dall-e-3';
        const size = options.size || '1024x1024';
        const quality = options.quality || 'standard';
        const style = options.style || 'vivid';
        const n = options.n || 1;
        const saveDir = options.saveDir || this.config.defaultSaveDir || process.cwd();
        const fileName = options.fileName || `dalle-${Date.now()}`;
    
        // Ensure save directory exists
        await fs.ensureDir(saveDir);
    
        // Make request to OpenAI API
        const response = await axios.post(
          `${this.baseUrl}/images/generations`,
          {
            model,
            prompt,
            n,
            size,
            quality,
            style,
            response_format: 'b64_json'
          },
          {
            headers: {
              'Content-Type': 'application/json',
              '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 imageBuffer = Buffer.from(item.b64_json, 'base64');
          let imagePath = path.join(saveDir, `${fileName}${n > 1 ? `-${i + 1}` : ''}.png`);
          
          // Ensure the path is absolute
          if (!path.isAbsolute(imagePath)) {
            imagePath = path.resolve(process.cwd(), imagePath);
          }
          
          await fs.writeFile(imagePath, imageBuffer);
          imagePaths.push(imagePath);
        }
    
        return {
          success: true,
          imagePaths,
          model,
          prompt
        };
      } catch (error) {
        console.log("DALL-E API Error:", error);
        
        let errorMessage = 'Failed to generate image';
        
        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
        };
      }
    }
  • Type definition for input arguments of the generate_image tool.
    export interface GenerateImageArgs {
      prompt: string;
      model?: string;
      size?: string;
      quality?: string;
      style?: string;
      n?: number;
      saveDir?: string;
      fileName?: string;
    }
  • Tool registration object defining name, description, inputSchema, and handler for 'generate_image'.
    {
      name: "generate_image",
      description: "Generate an image using DALL-E based on a text prompt",
      inputSchema: {
        type: "object",
        properties: {
          prompt: {
            type: "string",
            description: "Text description of the desired image"
          },
          model: {
            type: "string",
            description: "DALL-E model to use (dall-e-2 or dall-e-3)",
            enum: ["dall-e-2", "dall-e-3"]
          },
          size: {
            type: "string",
            description: "Size of the generated image",
            enum: ["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"]
          },
          quality: {
            type: "string",
            description: "Quality of the generated image (dall-e-3 only)",
            enum: ["standard", "hd"]
          },
          style: {
            type: "string",
            description: "Style of the generated image (dall-e-3 only)",
            enum: ["vivid", "natural"]
          },
          n: {
            type: "number",
            description: "Number of images to generate (1-10)",
            minimum: 1,
            maximum: 10
          },
          saveDir: {
            type: "string",
            description: "Directory to save the generated images"
          },
          fileName: {
            type: "string",
            description: "Base filename for the generated images (without extension)"
          }
        },
        required: ["prompt"]
      },
      handler: async (args: GenerateImageArgs): Promise<ToolResponse> => {
        const result = await dalleService.generateImage(args.prompt, {
          model: args.model,
          size: args.size,
          quality: args.quality,
          style: args.style,
          n: args.n,
          saveDir: args.saveDir,
          fileName: args.fileName
        });
    
        if (!result.success) {
          return {
            content: [{
              type: "text",
              text: `Error generating image: ${result.error}`
            }]
          };
        }
    
        const imagePaths = result.imagePaths || [];
        const imageCount = imagePaths.length;
        const model = result.model || 'dall-e-3';
    
        let responseText = `Successfully generated ${imageCount} image${imageCount !== 1 ? 's' : ''} using ${model}.\n\n`;
        responseText += `Prompt: "${result.prompt}"\n\n`;
        responseText += `Image${imageCount !== 1 ? 's' : ''} saved to:\n`;
        
        imagePaths.forEach(imagePath => {
          responseText += `- ${imagePath}\n`;
        });
    
        return {
          content: [{
            type: "text",
            text: responseText
          }]
        };
      }
    },
  • src/index.ts:24-32 (registration)
    MCP server capabilities registration enabling the 'generate_image' tool.
      capabilities: {
        tools: {
          generate_image: true,
          edit_image: true,
          create_variation: true,
          validate_key: true
        },
      },
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the basic function but omits critical behavioral details: whether this is a read-only or mutation operation, rate limits, authentication requirements, cost implications, or what happens when images are saved to 'saveDir'. For a complex 8-parameter tool with no annotation coverage, this is insufficient.

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 gets straight to the point with zero wasted words. It's appropriately sized for the tool's complexity and front-loads the essential information.

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 complex image generation tool with 8 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns (image URLs? file paths? metadata?), error conditions, or behavioral constraints. The agent would need to guess about the output format and operational characteristics.

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 fully documents all 8 parameters. The description adds no additional parameter information beyond what's in the schema, meeting the baseline expectation but not providing extra value. The description doesn't explain relationships between parameters (e.g., 'quality' and 'style' only apply to 'dall-e-3').

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 ('image using DALL-E based on a text prompt'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'create_variation' or 'edit_image', which likely also involve image generation/manipulation.

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 'create_variation' or 'edit_image'. It doesn't mention prerequisites, constraints, or typical use cases, leaving the agent to infer usage from the tool name alone.

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