Skip to main content
Glama
qhdrl12

Gemini Image Generator MCP Server

generate_image_from_text

Create images from text descriptions using Google's Gemini AI model. Provide a text prompt to generate visual content through the MCP protocol.

Instructions

Generate an image based on the given text prompt using Google's Gemini model.

Args:
    prompt: User's text prompt describing the desired image to generate
    
Returns:
    Path to the generated image file using Gemini's image generation capabilities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes

Implementation Reference

  • The handler function for the 'generate_image_from_text' tool. It is registered via the @mcp.tool() decorator. Translates the prompt, generates detailed contents using get_image_generation_prompt, processes the image generation via process_image_with_gemini, and handles errors.
    @mcp.tool()
    async def generate_image_from_text(prompt: str) -> Tuple[bytes, str]:
        """Generate an image based on the given text prompt using Google's Gemini model.
    
        Args:
            prompt: User's text prompt describing the desired image to generate
            
        Returns:
            Path to the generated image file using Gemini's image generation capabilities
        """
        try:
            # Translate the prompt to English
            translated_prompt = await translate_prompt(prompt)
            
            # Create detailed generation prompt
            contents = get_image_generation_prompt(translated_prompt)
            
            # Process with Gemini and return the result
            return await process_image_with_gemini([contents], prompt)
            
        except Exception as e:
            error_msg = f"Error generating image: {str(e)}"
            logger.error(error_msg)
            return error_msg
  • The @mcp.tool() decorator registers the generate_image_from_text function as an MCP tool.
    @mcp.tool()
  • Core helper function that calls the Gemini API for image generation/processing, generates filename, saves the image, and returns image bytes and path. Used by the handler.
    async def process_image_with_gemini(
        contents: List[Any], 
        prompt: str, 
        model: str = "gemini-2.0-flash-preview-image-generation"
    ) -> Tuple[bytes, str]:
        """Process an image request with Gemini and save the result.
        
        Args:
            contents: List containing the prompt and optionally an image
            prompt: Original prompt for filename generation
            model: Gemini model to use
            
        Returns:
            Path to the saved image file
        """
        # Call Gemini Vision API
        gemini_response = await call_gemini(
            contents,
            model=model,
            config=types.GenerateContentConfig(
                response_modalities=['Text', 'Image']
            )
        )
        
        # Generate a filename for the image
        filename = await convert_prompt_to_filename(prompt)
        
        # Save the image and return the path
        saved_image_path = await save_image(gemini_response, filename)
    
        return gemini_response, saved_image_path
  • Helper function that translates the input prompt to English using Gemini for better results. Called by the handler.
    async def translate_prompt(text: str) -> str:
        """Translate and optimize the user's prompt to English for better image generation results.
        
        Args:
            text: The original prompt in any language
            
        Returns:
            English translation of the prompt with preserved intent
        """
        try:
            # Create a prompt for translation with strict intent preservation
            prompt = get_translate_prompt(text)
    
            # Call Gemini and get the translated prompt
            translated_prompt = await call_gemini(prompt, text_only=True)
            logger.info(f"Original prompt: {text}")
            logger.info(f"Translated prompt: {translated_prompt}")
            
            return translated_prompt
        
        except Exception as e:
            logger.error(f"Error translating prompt: {str(e)}")
            # Return original text if translation fails
            return text
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the model and return type (path to image file) but lacks critical details such as rate limits, authentication requirements, image format, size, quality, or error handling. This is insufficient for a generative AI tool with potential costs and constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core functionality. The structured sections (Args, Returns) enhance readability, though the second sentence could be more integrated to avoid slight redundancy.

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

Completeness2/5

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

Given the complexity of image generation, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., costs, latency), output specifics (e.g., file format, resolution), and error cases, leaving significant gaps for an AI agent to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, but the description compensates by explaining the single parameter ('prompt') as 'User's text prompt describing the desired image to generate.' This adds meaningful context beyond the schema's basic type information, clarifying the parameter's role in the generation process.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Generate an image') and resource ('based on the given text prompt'), using Google's Gemini model. It distinguishes from sibling tools like 'transform_image_from_encoded' and 'transform_image_from_file' by specifying text-based generation rather than transformation from existing images.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for text-to-image generation but does not explicitly state when to use this tool versus alternatives. It mentions the model (Gemini) but provides no guidance on prerequisites, limitations, or scenarios where other tools might be more appropriate.

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/qhdrl12/mcp-server-gemini-image-generator'

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