Skip to main content
Glama
ECNU3D

Universal Image Generator MCP Server

by ECNU3D

transform_image_from_file

Modify existing images using text prompts to apply visual transformations through AI image generation providers.

Instructions

Transform an existing image file based on the given text prompt using the configured image provider.

    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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'transform_image_from_file' MCP tool. It is decorated with @mcp.tool() which also serves as registration. Loads image from file path, translates and prepares prompt, calls the image provider's transform_image method, saves the result, and returns the saved path or error.
    @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 the configured image provider.
    
        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:
            provider = get_image_provider()
            logger.info(f"Processing transform_image_from_file request with {provider.get_name()}")
            logger.info(f"Image file path: {image_file_path}")
            logger.info(f"Transformation prompt: {prompt}")
    
            # Validate file path
            if not os.path.exists(image_file_path):
                raise ValueError(f"Image file not found: {image_file_path}")
    
            # 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 
            
            # Translate the prompt for the provider
            translated_prompt = await translate_prompt_for_provider(prompt, provider)
            
            # Create detailed transformation prompt
            transformation_prompt = get_image_transformation_prompt(translated_prompt)
            
            # Process the transformation using the provider
            _, saved_path, remote_url = await provider.transform_image(source_image, transformation_prompt)
            
            logger.info(f"Image transformed and saved to: {saved_path}")
            
            # Prepare response with remote URL if available
            response = f"Image transformed and saved to: {saved_path}"
            if remote_url:
                response += f"\nRemote URL: {remote_url}"
            
            return response
            
        except Exception as e:
            error_msg = f"Error transforming image: {str(e)}"
            logger.error(error_msg)
            return error_msg
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 transforms an image based on a prompt and returns a file path, but does not cover critical aspects such as required permissions, rate limits, supported file formats, or potential side effects like overwriting files. It adds some context but leaves significant gaps for a mutation tool.

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 with the core purpose in the first sentence, followed by structured Args and Returns sections. Every sentence adds value, though the formatting with indentation is slightly verbose but still efficient.

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

Completeness4/5

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

Given the tool's complexity (image transformation with 2 parameters), no annotations, and an output schema present (which covers return values), the description is fairly complete. It explains the purpose, parameters, and return value, but could improve by addressing behavioral traits like error handling or provider-specific details.

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 explicitly lists and explains both parameters (image_file_path and prompt) in the Args section, adding meaning beyond the input schema which has 0% description coverage. This compensates well for the schema's lack of descriptions, though it could provide more details like format constraints or examples.

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 specific verb ('Transform') and resource ('existing image file'), and distinguishes it from siblings by specifying it works from a file path rather than text, encoded data, or URL inputs like the sibling tools generate_image_from_text, transform_image_from_encoded, and transform_image_from_url.

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 context by mentioning 'based on the given text prompt' and 'using the configured image provider,' but does not explicitly state when to use this tool versus alternatives like the sibling tools. It lacks clear exclusions or direct comparisons to other transformation methods.

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/ECNU3D/universal-image-generator-mcp'

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