Skip to main content
Glama

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
NameRequiredDescriptionDefault
aspectRatioNoAspect ratio preset (square/landscape/portrait).square
descriptionYesDetailed description of the image to generate. For better social media results, include details about colors, style and composition.
imagesNoOptional array of image file paths to use as visual context (absolute or relative).
outputPathNoPath where to save the image (optional). If not specified, saves in current directory. Can be a folder or complete path with filename.
styleNoAdditional style for the image (optional). Examples: "minimalist", "colorful", "professional", "artistic"
watermarkPathNoPath to watermark image file to overlay in a corner (optional)
watermarkPositionNoOptional watermark position when using `watermarkPath`.bottom-right

Implementation Reference

  • 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', }); } }
  • 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); }
  • 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 }

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/devexpert-io/gemini-image-mcp-server'

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