Skip to main content
Glama
georgejeffers

Gemini MCP Server

Generate Image

generate_image
Read-only

Create images from text descriptions using Gemini AI models. Specify prompts, aspect ratios, and resolutions to generate custom visual content.

Instructions

Generate an image from a text prompt using Gemini image models (Nano Banana Pro by default).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText description of the image to generate
modelNoImage generation model (Nano Banana Pro by default)gemini-3-pro-image-preview
aspectRatioNoAspect ratio of the generated image1:1
imageSizeNoImage resolution (1K or 2K)1K

Implementation Reference

  • The main handler function that executes the generate_image tool logic. It calls the Google GenAI API to generate an image from a text prompt, validates the response, extracts the image data, and returns it as MCP content.
    async ({ prompt, model, aspectRatio, imageSize }) => {
      try {
        const response = await ai.models.generateContent({
          model,
          contents: prompt,
          config: {
            responseModalities: ['TEXT', 'IMAGE'],
            imageConfig: { aspectRatio, imageSize },
          },
        });
    
        const image = extractImageFromResponse(response);
        if (!image) {
          return {
            content: [{ type: 'text' as const, text: 'No image was generated. Try a different prompt.' }],
            isError: true,
          };
        }
    
        if (!validateImageSize(image.data)) {
          return {
            content: [{ type: 'text' as const, text: 'Generated image exceeds size limit. Try 1K imageSize or a simpler prompt.' }],
            isError: true,
          };
        }
    
        return {
          content: [{ type: 'image' as const, data: image.data, mimeType: image.mimeType }],
        };
      } catch (error) {
        return formatToolError(error);
      }
    },
  • Input schema definition for the generate_image tool, defining the prompt (required), model (with default gemini-3-pro-image-preview), aspectRatio (with default 1:1), and imageSize (with default 1K) parameters.
    {
      title: 'Generate Image',
      description: 'Generate an image from a text prompt using Gemini image models (Nano Banana Pro by default).',
      inputSchema: {
        prompt: z.string().min(1).describe('Text description of the image to generate'),
        model: ImageModel.default('gemini-3-pro-image-preview').describe('Image generation model (Nano Banana Pro by default)'),
        aspectRatio: AspectRatio.default('1:1').describe('Aspect ratio of the generated image'),
        imageSize: ImageSize.default('1K').describe('Image resolution (1K or 2K)'),
      },
      annotations: {
        readOnlyHint: true,
        destructiveHint: false,
        openWorldHint: true,
      },
    },
  • Type definitions for the generate_image tool schema - ImageModel enum (gemini-2.5-flash-image, gemini-3-pro-image-preview), AspectRatio enum (various ratios), and ImageSize enum (1K, 2K, 4K).
    export const ImageModel = z.enum([
      'gemini-2.5-flash-image',
      'gemini-3-pro-image-preview',
    ]);
    export type ImageModel = z.infer<typeof ImageModel>;
    
    export const AspectRatio = z.enum([
      '1:1', '2:3', '3:2', '3:4', '4:3', '4:5', '5:4', '9:16', '16:9', '21:9',
    ]);
    export type AspectRatio = z.infer<typeof AspectRatio>;
    
    export const ImageSize = z.enum(['1K', '2K', '4K']);
    export type ImageSize = z.infer<typeof ImageSize>;
  • src/index.ts:29-29 (registration)
    Registration of the generate_image tool with the MCP server, passing the server instance and AI client to the register function.
    registerGenerateImage(server, ai);
  • Helper function extractImageFromResponse that parses the Google GenAI response to extract the inline image data and MIME type from the response parts.
    export function extractImageFromResponse(response: any): { data: string; mimeType: string } | null {
      const parts = response?.candidates?.[0]?.content?.parts;
      if (!parts) return null;
      for (const part of parts) {
        if (part.inlineData) {
          return {
            data: part.inlineData.data,
            mimeType: part.inlineData.mimeType,
          };
        }
      }
      return null;
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true, openWorldHint=true, and destructiveHint=false, covering safety and scope. The description adds minimal behavioral context by specifying 'Gemini image models' and a default model, but doesn't disclose rate limits, authentication needs, output format (e.g., image type), or cost implications. With annotations providing core behavioral traits, the description adds some value but lacks depth.

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 with zero wasted words. It front-loads the core purpose and includes relevant technical details (Gemini models, default model) without redundancy. Every element earns its place, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (image generation with 4 parameters), rich annotations (covering safety and scope), and 100% schema coverage, the description is adequate but incomplete. It lacks output details (no output schema), doesn't explain sibling relationships, and omits behavioral nuances like rate limits. However, annotations and schema compensate significantly, making it minimally viable for basic use.

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%, with all parameters well-documented in the schema itself (e.g., prompt description, model enum with default, aspect ratio options, image size options). The description only mentions the default model ('Nano Banana Pro by default'), which partially overlaps with schema info. It adds negligible semantic value beyond the schema, meeting the baseline for high coverage.

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 tool's purpose: 'Generate an image from a text prompt using Gemini image models.' It specifies the verb ('Generate'), resource ('image'), and technology ('Gemini image models'), but doesn't explicitly differentiate from sibling tools like 'edit_image' or 'generate_text' beyond mentioning image generation. The default model mention adds specificity but doesn't fully address sibling differentiation.

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. It doesn't mention sibling tools like 'edit_image' (for modifying existing images) or 'generate_text' (for text generation), nor does it specify use cases, prerequisites, or exclusions. The agent must 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/georgejeffers/gemini-mcp-server'

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