Skip to main content
Glama
m-mcp

Flux Schnell Server

by m-mcp

image_generation

Generate images from text prompts using the Flux Schnell model. Create custom visuals with adjustable dimensions and seed values for consistent results.

Instructions

Generate an image from a prompt.
Args:
    prompt (str): 生成图片的提示词
    image_size (int, optional): 生成图片的大小. Defaults to 512.
Returns:
    str: 生成的图片的base64编码

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
image_widthNo
image_heightNo
seedNo

Implementation Reference

  • main.py:7-56 (handler)
    The handler function for the 'image_generation' tool, decorated with @server.tool() for registration in FastMCP. It generates an image using the Flux Schnell model hosted on Hugging Face Spaces by sending a POST request with the prompt and parameters, then retrieves the image URL via streaming.
    @server.tool()
    async def image_generation(prompt: str, image_width: int = 512, image_height: int = 512, seed: int = 3):
        """
        Generate an image from a prompt.
        Args:
            prompt (str): 生成图片的提示词
            image_size (int, optional): 生成图片的大小. Defaults to 512.
        Returns:
            str: 生成的图片的base64编码
        """
        async with httpx.AsyncClient() as client:
            try:
                # 创建图片生成请求
                # data: [提示词, seed种子, 是否使用随机种子, 图片宽, 图片高, 步长]
                response = await client.post(
                    "https://black-forest-labs-flux-1-schnell.hf.space/call/infer",
                    json={"data": [prompt, 0, True, image_width, image_height, seed]},
                    headers={"Content-Type": "application/json"},
                )
                response.raise_for_status()
                response_data = response.json()
    
                event_id = response_data.get("event_id")
                if not event_id:
                    return "Failed to generate image: No event_id received."
    
                # 构造流式获取图片的URL
                url = f"https://black-forest-labs-flux-1-schnell.hf.space/call/infer/{event_id}"
                full_response = ""
    
                # 获取图片数据
                async with client.stream("GET", url) as stream_response:
                    stream_response.raise_for_status()
                    async for chunk in stream_response.aiter_text():
                        full_response += chunk
    
                # 解析最终图片URL
                data_parts = full_response.split("data: ")
                if len(data_parts) < 2:
                    return "Failed to parse image response."
    
                image_data = json.loads(data_parts[-1])
                return image_data[0]["url"]
    
            except httpx.HTTPStatusError as e:
                return f"HTTP error occurred: {e.response.status_code} {e.response.text}"
            except json.JSONDecodeError:
                return "Failed to decode JSON response."
            except Exception as e:
                return f"An unexpected error occurred: {str(e)}"
Behavior2/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 states the basic action (generation) and return format (base64), but lacks critical behavioral information such as rate limits, processing time, quality expectations, model details, or error conditions. For a generative AI tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief but has structural issues. It front-loads the core purpose, but the parameter documentation is inconsistent with the actual schema. The bilingual nature (English description with Chinese parameter documentation) creates confusion. While concise, the structural problems reduce its effectiveness.

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

Completeness2/5

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

For an image generation tool with 4 parameters, 0% schema description coverage, no annotations, and no output schema, the description is incomplete. It doesn't explain the generation process, quality factors, limitations, or what the base64 output represents. The parameter mismatch between description and schema creates additional confusion.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It documents 'prompt' and 'image_size' parameters, but the input schema actually has 'prompt', 'image_width', 'image_height', and 'seed' - with 'image_size' not matching the schema's separate width/height parameters. This creates confusion and doesn't adequately cover the 4 parameters, especially missing 'seed' entirely.

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 with 'Generate an image from a prompt' - a specific verb ('Generate') and resource ('image'). It distinguishes itself by focusing on image generation from text prompts. However, without sibling tools, it doesn't need to differentiate from alternatives, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any prerequisites, limitations, or typical use cases. The only contextual information is the parameter documentation, which doesn't constitute usage guidance.

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/m-mcp/flux-schnell-server'

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