generate_image
Create custom images using Google Gemini AI from text descriptions, with options for aspect ratios, visual references, styles, and watermark overlays to produce tailored visual content.
Instructions
Create a new image using Google Gemini AI from a text description, optionally providing reference images to guide the result. Use the edit_image tool when you need to modify an existing asset.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aspectRatio | No | Aspect ratio preset (square/landscape/portrait). | square |
| description | Yes | Detailed description of the image to generate. For better social media results, include details about colors, style and composition. | |
| images | No | Optional array of image file paths to use as visual context (absolute or relative). | |
| outputPath | No | Path where to save the image (optional). If not specified, saves in current directory. Can be a folder or complete path with filename. | |
| style | No | Additional style for the image (optional). Examples: "minimalist", "colorful", "professional", "artistic" | |
| watermarkPath | No | Path to watermark image file to overlay in a corner (optional) | |
| watermarkPosition | No | Optional watermark position when using `watermarkPath`. | bottom-right |
Implementation Reference
- src/tools/generateImage.ts:53-85 (handler)The handler function that implements the core logic of the 'generate_image' tool. It validates input, calls GeminiService to generate the image, saves it using ImageService, and returns the file path.export async function handleGenerateImage( args: GenerateImageArgs, geminiService: GeminiService, imageService: ImageService ) { if (!args.description || !args.description.trim()) { throw invalidParams('Description is required to generate an image'); } try { const imageData = await geminiService.generateImage(args); const filePath = await imageService.saveImage(imageData, { outputPath: args.outputPath, description: args.description, watermarkPath: args.watermarkPath, watermarkPosition: args.watermarkPosition }); return { content: [ { type: 'text', text: filePath, }, ], }; } catch (error) { throw ensureMcpError(error, ErrorCode.InternalError, 'Failed to generate image', { stage: 'generate_image.tool', }); } }
- src/tools/generateImage.ts:8-51 (schema)The Tool object definition for 'generate_image', including the name, description, and detailed inputSchema for validation.export const generateImageTool: Tool = { name: 'generate_image', description: 'Create a new image using Google Gemini AI from a text description, optionally providing reference images to guide the result. Use the `edit_image` tool when you need to modify an existing asset.', inputSchema: { type: 'object', properties: { description: { type: 'string', description: 'Detailed description of the image to generate. For better social media results, include details about colors, style and composition.', }, images: { type: 'array', items: { type: 'string' }, description: 'Optional array of image file paths to use as visual context (absolute or relative).', }, watermarkPosition: { type: 'string', enum: ['top-left', 'top-right', 'bottom-left', 'bottom-right'], description: 'Optional watermark position when using `watermarkPath`.', default: 'bottom-right', }, aspectRatio: { type: 'string', enum: ['square', 'landscape', 'portrait'], description: 'Aspect ratio preset (square/landscape/portrait).', default: 'square', }, style: { type: 'string', description: 'Additional style for the image (optional). Examples: "minimalist", "colorful", "professional", "artistic"', }, outputPath: { type: 'string', description: 'Path where to save the image (optional). If not specified, saves in current directory. Can be a folder or complete path with filename.', }, watermarkPath: { type: 'string', description: 'Path to watermark image file to overlay in a corner (optional)', }, }, required: ['description'], }, };
- src/index.ts:58-62 (registration)Registration of the 'generate_image' tool in the MCP server's listTools handler, making it discoverable to clients.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [generateImageTool, editImageTool], }; });
- src/index.ts:66-69 (registration)Dispatch logic in the MCP server's callTool handler that routes 'generate_image' requests to the handleGenerateImage function.if (request.params.name === 'generate_image') { const args = request.params.arguments as unknown as GenerateImageArgs; return await handleGenerateImage(args, this.geminiService, this.imageService); }
- src/types/index.ts:1-9 (schema)TypeScript interface defining the input arguments for the generate_image tool.export interface GenerateImageArgs { description: string; aspectRatio?: 'square' | 'portrait' | 'landscape'; style?: string; outputPath?: string; watermarkPath?: string; watermarkPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; images?: string[]; // Optional array of image paths used as visual context }