generate-image
Create custom images from text prompts with configurable settings like aspect ratio, resolution, and output format. Save results to a specified directory.
Instructions
Generate an image based on a prompt
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aspect_ratio | No | ||
| filename | No | Base filename to save the image(s) with | |
| go_fast | No | ||
| megapixels | No | ||
| num_inference_steps | No | ||
| num_outputs | No | ||
| output_dir | Yes | Full absolute path to output directory. For Windows, use double backslashes like 'C:\\Users\\name\\path'. For Unix/Mac use '/path/to/dir'. Always use the proper path otherwise you will get an error. | |
| output_format | No | ||
| output_quality | No | ||
| prompt | Yes |
Implementation Reference
- src/server.ts:34-51 (handler)Handler function for the 'generate-image' tool. It calls imageService.generateImages(params) and returns the JSON stringified result or error message.async (params) => { try { const result = await imageService.generateImages(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } }
- src/server.ts:22-33 (schema)Zod input schema definition for the 'generate-image' tool parameters.{ prompt: z.string(), output_dir: z.string().describe("Full absolute path to output directory. For Windows, use double backslashes like 'C:\\\\Users\\\\name\\\\path'. For Unix/Mac use '/path/to/dir'. Always use the proper path otherwise you will get an error."), filename: z.string().optional().describe("Base filename to save the image(s) with"), go_fast: z.boolean().optional(), megapixels: z.enum(["1", "2", "4"]).optional(), num_outputs: z.number().min(1).max(4).optional(), aspect_ratio: z.enum(["1:1", "4:3", "16:9"]).optional(), output_format: z.enum(["webp", "png", "jpeg"]).optional(), output_quality: z.number().min(1).max(100).optional(), num_inference_steps: z.number().min(4).max(20).optional() },
- src/server.ts:19-52 (registration)Registration of the 'generate-image' tool on the MCP server using server.tool() with name, description, schema, and handler.server.tool( "generate-image", "Generate an image based on a prompt", { prompt: z.string(), output_dir: z.string().describe("Full absolute path to output directory. For Windows, use double backslashes like 'C:\\\\Users\\\\name\\\\path'. For Unix/Mac use '/path/to/dir'. Always use the proper path otherwise you will get an error."), filename: z.string().optional().describe("Base filename to save the image(s) with"), go_fast: z.boolean().optional(), megapixels: z.enum(["1", "2", "4"]).optional(), num_outputs: z.number().min(1).max(4).optional(), aspect_ratio: z.enum(["1:1", "4:3", "16:9"]).optional(), output_format: z.enum(["webp", "png", "jpeg"]).optional(), output_quality: z.number().min(1).max(100).optional(), num_inference_steps: z.number().min(4).max(20).optional() }, async (params) => { try { const result = await imageService.generateImages(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } } );
- src/types.ts:1-12 (schema)TypeScript interface defining ImageGenerationParams, matching the input schema for generate-image tool.export interface ImageGenerationParams { prompt: string; output_dir: string; filename?: string; go_fast?: boolean; megapixels?: "1" | "2" | "4"; num_outputs?: number; aspect_ratio?: "1:1" | "4:3" | "16:9"; output_format?: "webp" | "png" | "jpeg"; output_quality?: number; num_inference_steps?: number; }