Skip to main content
Glama
ECNU3D

Universal Image Generator MCP Server

by ECNU3D

generate_image_from_text

Create images from text descriptions using AI models. Enter a text prompt to generate corresponding images through multiple provider options.

Instructions

Generate an image based on the given text prompt using the configured image provider.

Args:
    prompt: User's text prompt describing the desired image to generate
    model_type: Optional model type for Google provider ("gemini" or "imagen"). 
               If not specified, uses the default from GOOGLE_MODEL env var.
    
Returns:
    Path to the generated image file using the configured provider's image generation capabilities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
model_typeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • This is the main handler function for the 'generate_image_from_text' tool, decorated with @mcp.tool() which also serves as the registration. It handles the logic to generate an image from text prompt using the configured provider (Google, ZhipuAI, or Bailian), including prompt preparation, translation, generation, and saving the image.
    @mcp.tool()
    async def generate_image_from_text(prompt: str, model_type: Optional[str] = None) -> str:
        """Generate an image based on the given text prompt using the configured image provider.
    
        Args:
            prompt: User's text prompt describing the desired image to generate
            model_type: Optional model type for Google provider ("gemini" or "imagen"). 
                       If not specified, uses the default from GOOGLE_MODEL env var.
            
        Returns:
            Path to the generated image file using the configured provider's image generation capabilities
        """
        try:
            provider = get_image_provider()
            if not provider.supports_generation():
                return f"Error: {provider.get_name()} provider does not support image generation"
            
            logger.info(f"Generating image with {provider.get_name()} provider")
            logger.info(f"User prompt: {prompt}")
            if model_type:
                logger.info(f"Model type specified: {model_type}")
            
            # Prepare the optimized prompt for the provider
            optimized_prompt = await prepare_prompt_for_provider(prompt, provider, model_type)
            
            # Generate the image using the provider with optional model_type
            kwargs = {}
            if model_type and provider.get_name() == "google":
                kwargs['model_type'] = model_type
            
            _, saved_path, remote_url = await provider.generate_image(optimized_prompt, **kwargs)
            
            logger.info(f"Image generated and saved to: {saved_path}")
            
            # Prepare response with remote URL if available
            response = f"Image saved to: {saved_path}"
            if remote_url:
                response += f"\nRemote URL: {remote_url}"
            
            return response
            
        except Exception as e:
            error_msg = f"Error generating image: {str(e)}"
            logger.error(error_msg)
            return error_msg
  • The @mcp.tool() decorator registers this function as an MCP tool.
    @mcp.tool()
  • The function signature and docstring define the input schema (prompt: str required, model_type: Optional[str]), and output as str (path to image). FastMCP uses this for tool schema.
    async def generate_image_from_text(prompt: str, model_type: Optional[str] = None) -> str:
        """Generate an image based on the given text prompt using the configured image provider.
    
        Args:
            prompt: User's text prompt describing the desired image to generate
            model_type: Optional model type for Google provider ("gemini" or "imagen"). 
                       If not specified, uses the default from GOOGLE_MODEL env var.
            
        Returns:
            Path to the generated image file using the configured provider's image generation capabilities
        """
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 the tool 'generates' an image, implying a write/mutation operation, and notes it uses a 'configured image provider' with optional model types. However, it lacks details on permissions, rate limits, error handling, or what 'configured' entails. The description adds some context but leaves significant behavioral aspects unspecified.

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, starting with the core purpose, followed by Args and Returns sections. Each sentence adds value: the first states the action, the second explains parameters with useful details, and the third specifies the return value. There is no wasted text, 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.

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 generation with provider configuration), no annotations, and an output schema (implied by the Returns section), the description is reasonably complete. It covers the purpose, parameters, and return value. However, it could benefit from more behavioral context (e.g., provider setup, limitations) to fully address the tool's operational aspects, though the output schema reduces the need for return value details.

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

Parameters5/5

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

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explains that 'prompt' is the 'User's text prompt describing the desired image to generate' and clarifies 'model_type' as an 'Optional model type for Google provider' with values 'gemini' or 'imagen,' including default behavior. This fully compensates for the schema's lack of descriptions, providing clear semantics for both parameters.

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

Purpose4/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: 'Generate an image based on the given text prompt using the configured image provider.' It specifies the verb (generate), resource (image), and input source (text prompt). However, it doesn't explicitly differentiate from sibling tools like transform_image_from_file or transform_image_from_url, which appear to handle different input types rather than text-to-image generation.

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 through phrases like 'based on the given text prompt' and 'using the configured image provider,' suggesting this tool is for text-to-image generation. However, it doesn't explicitly state when to use this tool versus its siblings (e.g., transform_image_from_file for file-based inputs) or provide any exclusion criteria. The guidance is present but not comprehensive.

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