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

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 """

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