Skip to main content
Glama
sungmin-koo-ai

Gemini Image Generator MCP

transform_image_from_file

Modify existing image files using text prompts with Google's Gemini AI. Upload an image and describe changes to generate transformed versions automatically saved locally.

Instructions

Transform an existing image file based on the given text prompt using Google's Gemini model.

Args:
    image_file_path: Path to the image file to be transformed
    prompt: Text prompt describing the desired transformation or modifications
    
Returns:
    Path to the transformed image file saved on the server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_file_pathYes
promptYes

Implementation Reference

  • The @mcp.tool()-decorated function that serves as both the registration and the handler for the 'transform_image_from_file' tool. It validates the image file path, loads the image using PIL, translates the prompt, and delegates to process_image_transform for Gemini API interaction.
    @mcp.tool()
    async def transform_image_from_file(image_file_path: str, prompt: str) -> str:
        """Transform an existing image file based on the given text prompt using Google's Gemini model.
    
        Args:
            image_file_path: Path to the image file to be transformed
            prompt: Text prompt describing the desired transformation or modifications
            
        Returns:
            Path to the transformed image file saved on the server
        """
        try:
            logger.info(f"Processing transform_image_from_file request with prompt: {prompt}")
            logger.info(f"Image file path: {image_file_path}")
    
            # Validate file path
            if not os.path.exists(image_file_path):
                raise ValueError(f"Image file not found: {image_file_path}")
    
            # Translate the prompt to English
            translated_prompt = await translate_prompt(prompt)
                
            # Load the source image directly using PIL
            try:
                source_image = PIL.Image.open(image_file_path)
                logger.info(f"Successfully loaded image from file: {image_file_path}")
            except PIL.UnidentifiedImageError:
                logger.error("Error: Could not identify image format")
                raise ValueError("Could not identify image format. Supported formats include PNG, JPEG, GIF, WebP.")
            except Exception as e:
                logger.error(f"Error: Could not load image: {str(e)}")
                raise 
            
            # Process the transformation
            return await process_image_transform(source_image, translated_prompt, prompt)
            
        except Exception as e:
            error_msg = f"Error transforming image: {str(e)}"
            logger.error(error_msg)
            return error_msg
  • Helper function called by the tool handler to create transformation instructions and process the image with Gemini via process_image_with_gemini.
    async def process_image_transform(
        source_image: PIL.Image.Image, 
        optimized_edit_prompt: str, 
        original_edit_prompt: str
    ) -> str:
        """Process image transformation with Gemini.
        
        Args:
            source_image: PIL Image object to transform
            optimized_edit_prompt: Optimized text prompt for transformation
            original_edit_prompt: Original user prompt for naming
            
        Returns:
            Path to the transformed image file
        """
        # Create prompt for image transformation
        edit_instructions = get_image_transformation_prompt(optimized_edit_prompt)
        
        # Process with Gemini and return the result
        return await process_image_with_gemini(
            [edit_instructions, source_image],
            original_edit_prompt
        )
Behavior3/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 that the tool saves the transformed file on the server, which is useful context beyond basic functionality. However, it lacks details on permissions, rate limits, error handling, or what transformations are possible, leaving behavioral gaps.

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 well-structured and front-loaded with the core purpose, followed by clear sections for Args and Returns. Every sentence earns its place by providing essential information without redundancy, making it efficient and easy to parse.

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 complexity of an AI-based image transformation tool with no annotations and no output schema, the description is moderately complete. It covers the basic operation and return value but lacks details on supported image formats, transformation limits, or error cases, which are important for such a tool.

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 description adds significant meaning beyond the input schema, which has 0% coverage. It explains that 'image_file_path' is for an existing image file to be transformed and 'prompt' describes the desired transformation, clarifying the purpose and usage of both parameters effectively.

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 tool's purpose with a specific verb ('Transform') and resource ('an existing image file'), and distinguishes it from siblings by specifying it works from a file path rather than text or encoded input. The phrase 'using Google's Gemini model' adds technical specificity.

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

Usage Guidelines4/5

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

The description implicitly provides usage context by mentioning 'existing image file' and the Gemini model, which suggests when to use this tool. However, it doesn't explicitly state when to choose this over sibling tools like 'transform_image_from_encoded' or 'generate_image_from_text', missing explicit alternative guidance.

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/sungmin-koo-ai/GeminiImageMCP'

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