Skip to main content
Glama
ECNU3D

Universal Image Generator MCP Server

by ECNU3D

transform_image_from_url

Transform existing images from URLs using AI editing functions like stylization, resolution enhancement, watermark removal, and content modification based on text prompts.

Instructions

Transform an existing image from a URL using the configured image provider.

    Args:
        image_url: Remote or Public URL of the image to be transformed
        prompt: Text prompt describing the desired transformation or modifications
        function: WanX editing function (default: 'description_edit'). Supported functions:
                 'description_edit', 'description_edit_with_mask', 'stylization_all', 
                 'stylization_local', 'remove_watermark', 'expand', 'super_resolution', 
                 'colorization', 'doodle', 'control_cartoon_feature'
        mask_image_url: URL of mask image (required for 'description_edit_with_mask')
        
    Returns:
        Details about the transformed image including local path and remote URL
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlYes
promptYes
functionNodescription_edit
mask_image_urlNo

Implementation Reference

  • The core handler function for the 'transform_image_from_url' MCP tool. It is decorated with @mcp.tool() for automatic registration and schema inference from signature/docstring. Handles provider-specific logic for downloading images from URL, prompt translation/optimization, and transformation via the image provider.
    @mcp.tool()
    async def transform_image_from_url(image_url: str, prompt: str, function: str = "description_edit", mask_image_url: Optional[str] = None) -> str:
        """Transform an existing image from a URL using the configured image provider.
    
        Args:
            image_url: Remote or Public URL of the image to be transformed
            prompt: Text prompt describing the desired transformation or modifications
            function: WanX editing function (default: 'description_edit'). Supported functions:
                     'description_edit', 'description_edit_with_mask', 'stylization_all', 
                     'stylization_local', 'remove_watermark', 'expand', 'super_resolution', 
                     'colorization', 'doodle', 'control_cartoon_feature'
            mask_image_url: URL of mask image (required for 'description_edit_with_mask')
            
        Returns:
            Details about the transformed image including local path and remote URL
        """
        try:
            provider = get_image_provider()
            logger.info(f"Processing transform_image_from_url request with {provider.get_name()}")
            logger.info(f"Image URL: {image_url}")
            logger.info(f"Transformation prompt: {prompt}")
            logger.info(f"Function: {function}")
    
            # For providers that don't support URL-based transformation, we need to download and convert
            if provider.get_name() == "google":
                # Download image and convert to PIL Image for Google
                import requests
                response = requests.get(image_url)
                if response.status_code != 200:
                    raise ValueError(f"Failed to download image from URL: {image_url}")
                
                source_image = PIL.Image.open(BytesIO(response.content))
                logger.info(f"Downloaded and loaded image from URL for Google")
                
                # 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)
                
            elif provider.get_name() == "bailian":
                # For Bailian, we can use the URL directly
                
                # 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)
                
                # Prepare kwargs for Bailian provider
                kwargs = {
                    'function': function,
                    'base_image_url': image_url
                }
                
                # Add mask image URL if provided and function requires it
                if mask_image_url:
                    kwargs['mask_image_url'] = mask_image_url
                elif function == "description_edit_with_mask":
                    raise ValueError("mask_image_url is required for description_edit_with_mask function")
                
                # Use a dummy PIL image since we're passing URL via kwargs
                dummy_image = PIL.Image.new('RGB', (1, 1))
                
                # Process the transformation using the provider
                _, saved_path, remote_url = await provider.transform_image(dummy_image, transformation_prompt, **kwargs)
                
            else:
                # For other providers, download image first
                import requests
                response = requests.get(image_url)
                if response.status_code != 200:
                    raise ValueError(f"Failed to download image from URL: {image_url}")
                
                source_image = PIL.Image.open(BytesIO(response.content))
                logger.info(f"Downloaded and loaded image from URL")
                
                # 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 from URL: {str(e)}"
            logger.error(error_msg)
            return error_msg

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