Skip to main content
Glama
ECNU3D

Universal Image Generator MCP Server

by ECNU3D

transform_image_from_url

Modify existing images from URLs using AI editing functions like stylization, watermark removal, resolution enhancement, and content transformation 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
functionNodescription_edit
image_urlYes
mask_image_urlNo
promptYes

Implementation Reference

  • The handler function for the 'transform_image_from_url' MCP tool, registered with @mcp.tool(). It handles image transformation from a URL, supporting multiple providers (Google, Bailian, etc.) by downloading images if needed, translating prompts, and delegating to the provider's transform_image method.
    @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
  • The @mcp.tool() decorator registers the transform_image_from_url function as an MCP tool.
    @mcp.tool()
  • The docstring provides the input schema (parameters and descriptions) and output description for the tool.
    """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 """

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