generate_image
Generate AI images using Azure DALL-E 3 or FLUX models. Describe your desired image in natural language, choose models and dimensions, and create visuals for various applications.
Instructions
π¨ Create stunning AI-generated images using Azure DALL-E 3 or FLUX models with intelligent model selection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Describe the image you want to create in natural language. Be detailed for best results. Examples: "A serene mountain landscape at sunset", "Modern minimalist logo design", "Cute cartoon mascot for a coffee shop" | |
| model | No | Choose AI model: "dall-e-3" (photorealistic, artistic), "flux" (creative, flexible), or "auto" (smart selection based on prompt) | auto |
| size | No | Image dimensions: Square (1024x1024) for social media, Wide (1792x1024) for banners, Tall (1024x1792) for posters | 1024x1024 |
| style | No | Visual style (DALL-E only): "vivid" for dramatic/artistic, "natural" for realistic/subdued | vivid |
| quality | No | Image quality (DALL-E only): "standard" for faster generation, "hd" for higher detail | standard |
Implementation Reference
- azure-image-generation-server.js:103-151 (handler)The core handler function that implements the logic for the 'generate_image' tool. It destructures input arguments, selects the model, calls the appropriate image generation method (DALL-E or FLUX), handles the response, and formats the output with text and base64-encoded image data.async generateImage(args) { const startTime = Date.now(); // Starting image generation const { prompt, model: requestedModel = 'auto', size = '1024x1024', style = 'vivid', quality = 'standard' } = args; if (!prompt) { throw new Error('Prompt is required for image generation'); } try { const modelSelectionStart = Date.now(); const selectedModel = this.selectModel(prompt, requestedModel); const modelSelectionTime = Date.now() - modelSelectionStart; // Model selection and generation setup complete const apiCallStart = Date.now(); let result; if (selectedModel === 'dall-e-3') { result = await this.generateWithDallE(prompt, size, style, quality); } else { result = await this.generateWithFlux(prompt, size); } const apiCallTime = Date.now() - apiCallStart; const totalTime = Date.now() - startTime; // Image generation completed successfully return { content: [ { type: 'text', text: `π¨ **Your AI-Generated Image is Ready!**\n\nβ¨ **Created from:** "${prompt}"\nπ€ **AI Model:** ${selectedModel.toUpperCase()} ${selectedModel === 'dall-e-3' ? '(Photorealistic AI)' : '(Creative AI)'}\nπ **Size:** ${size}\nβ±οΈ **Generation Time:** ${(totalTime / 1000).toFixed(1)}s\n${requestedModel === 'auto' ? `π§ **Smart Selection:** Chose ${selectedModel.toUpperCase()} based on your prompt\n` : ''}\nπΌοΈ Your custom image has been generated and is displayed below. Feel free to save, share, or use it however you'd like!` }, { type: 'image', mimeType: 'image/png', data: result.imageData } ] }; } catch (error) { const totalTime = Date.now() - startTime; console.error(`β [MCP] Error after ${totalTime}ms:`, error); throw new Error(`Failed to generate image: ${error.message}`); } }
- The input schema for the 'generate_image' tool, defining the structure and validation for parameters: prompt (required), model (with enum and default), size, style, and quality.inputSchema: { type: 'object', properties: { prompt: { type: 'string', description: 'Describe the image you want to create in natural language. Be detailed for best results. Examples: "A serene mountain landscape at sunset", "Modern minimalist logo design", "Cute cartoon mascot for a coffee shop"' }, model: { type: 'string', description: 'Choose AI model: "dall-e-3" (photorealistic, artistic), "flux" (creative, flexible), or "auto" (smart selection based on prompt)', enum: ['dall-e-3', 'flux', 'auto'], default: 'auto' }, size: { type: 'string', description: 'Image dimensions: Square (1024x1024) for social media, Wide (1792x1024) for banners, Tall (1024x1792) for posters', enum: ['1024x1024', '1792x1024', '1024x1792'], default: '1024x1024' }, style: { type: 'string', description: 'Visual style (DALL-E only): "vivid" for dramatic/artistic, "natural" for realistic/subdued', enum: ['vivid', 'natural'], default: 'vivid' }, quality: { type: 'string', description: 'Image quality (DALL-E only): "standard" for faster generation, "hd" for higher detail', enum: ['standard', 'hd'], default: 'standard' } }, required: ['prompt']
- azure-image-generation-server.js:35-76 (registration)Tool registration in the ListToolsRequestHandler. Responds with the 'generate_image' tool's name, description, and input schema when clients query available tools.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'generate_image', description: 'π¨ Create stunning AI-generated images using Azure DALL-E 3 or FLUX models with intelligent model selection', inputSchema: { type: 'object', properties: { prompt: { type: 'string', description: 'Describe the image you want to create in natural language. Be detailed for best results. Examples: "A serene mountain landscape at sunset", "Modern minimalist logo design", "Cute cartoon mascot for a coffee shop"' }, model: { type: 'string', description: 'Choose AI model: "dall-e-3" (photorealistic, artistic), "flux" (creative, flexible), or "auto" (smart selection based on prompt)', enum: ['dall-e-3', 'flux', 'auto'], default: 'auto' }, size: { type: 'string', description: 'Image dimensions: Square (1024x1024) for social media, Wide (1792x1024) for banners, Tall (1024x1792) for posters', enum: ['1024x1024', '1792x1024', '1024x1792'], default: '1024x1024' }, style: { type: 'string', description: 'Visual style (DALL-E only): "vivid" for dramatic/artistic, "natural" for realistic/subdued', enum: ['vivid', 'natural'], default: 'vivid' }, quality: { type: 'string', description: 'Image quality (DALL-E only): "standard" for faster generation, "hd" for higher detail', enum: ['standard', 'hd'], default: 'standard' } }, required: ['prompt'] } } ] }));
- azure-image-generation-server.js:79-87 (registration)Tool call dispatch registration in the CallToolRequestHandler. Routes 'generate_image' tool invocations to the generateImage handler method.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; if (name === 'generate_image') { return await this.generateImage(args); } throw new Error(`Unknown tool: ${name}`); });
- Helper method for intelligent model selection between 'dall-e-3' and 'flux' based on explicit user request or prompt keywords.selectModel(prompt, requestedModel) { if (requestedModel !== 'auto') { return requestedModel; } // Check if user explicitly mentions DALL-E const lowerPrompt = prompt.toLowerCase(); const isDalleRequest = ['dall-e', 'dalle', 'dall e'].some(keyword => lowerPrompt.includes(keyword)); return isDalleRequest ? 'dall-e-3' : 'flux'; }