Skip to main content
Glama

generate_flux_image

Generate images using the Flux model by submitting a text prompt via the Modal MCP Toolbox, designed for Python code execution and image creation in a sandbox environment.

Instructions

Let's you generate an image using the Flux model.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe prompt to generate an image for

Implementation Reference

  • The handler function for the 'generate_flux_image' tool. It ensures the Modal app is deployed, calls the remote inference method on the Model class with the prompt, and converts the resulting image bytes to ImageContent with annotations.
    async def generate_flux_image(prompt: Annotated[str, Field(description="The prompt to generate an image for")], ctx: Context) -> ImageContent:
        """Let's you generate an image using the Flux model."""
        await _ensure_app_deployment_is_up_to_date(ctx)
    
        cls = modal.Cls.from_name(app_name, Model.__name__)
        image_bytes = await cls().inference.remote.aio(prompt)
        image_content = Image(data=image_bytes, format=IMAGE_FORMAT).to_image_content()
        image_content.annotations = Annotations(audience=["user", "assistant"], priority=0.5)
        return image_content
  • Registration of the 'generate_flux_image' tool with the FastMCP server.
    server.add_tool(generate_flux_image)
  • The Modal class 'Model' that loads the FluxPipeline, sets it up on GPU, and provides the 'inference' method to generate image bytes from a prompt using the Flux model.
    @app.cls(
        gpu="L40S",
        container_idle_timeout=5 * MINUTES,
        image=flux_image,
        volumes={
            "/cache": modal.Volume.from_name("hf-hub-cache", create_if_missing=True),
        },
        enable_memory_snapshot=True,
    )
    class Model:
        @modal.enter(snap=True)
        def load(self):
            print("🔄 loading model...")
            pipe = FluxPipeline.from_pretrained(f"black-forest-labs/FLUX.1-{VARIANT}", torch_dtype=torch.bfloat16)
            self.pipe = _optimize(pipe)
    
        @modal.enter(snap=False)
        def setup(self):
            print("🔄 moving model to GPU...")
            self.pipe = self.pipe.to("cuda")
    
        @modal.method()
        def inference(self, prompt: str) -> bytes:
            print("🎨 generating image...")
            out = self.pipe(
                prompt,
                output_type="pil",
                num_inference_steps=NUM_INFERENCE_STEPS,
            ).images[0]
    
            byte_stream = BytesIO()
            out.save(byte_stream, format=IMAGE_FORMAT)
            return byte_stream.getvalue()
  • Helper function called by the handler to ensure the Modal app deployment is up to date by checking version and deploying if necessary.
    async def _ensure_app_deployment_is_up_to_date(ctx: Context):
        try:
            fn = modal.Function.from_name(app_name, "get_version")
            remote_version = await fn.remote.aio()
    
            if remote_version != version("modal_mcp_toolbox"):
                await ctx.info("App is out of date. Deploying ...")
                logger.info("App is out of date. Deploying ...")
                deploy_app(app)
        except NotFoundError:
            await ctx.info("App not found. Deploying...")
            logger.info("App not found. Deploying...")
            deploy_app(app)
  • Input schema definition via Annotated Field for the 'prompt' parameter.
    async def generate_flux_image(prompt: Annotated[str, Field(description="The prompt to generate an image for")], ctx: Context) -> ImageContent:
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool generates an image but doesn't disclose any behavioral traits such as rate limits, authentication needs, output format, or potential side effects. This leaves significant gaps for an AI agent to understand how to invoke it correctly.

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

Conciseness4/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, though it could be slightly more structured by including key details like output type or usage context.

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?

Given the tool's complexity (image generation with no annotations and no output schema), the description is incomplete. It lacks information on behavioral aspects, output format, and usage guidelines. Without annotations or an output schema, the description should provide more context to be fully helpful for an AI agent.

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

Parameters3/5

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

The input schema has 100% description coverage, with the single parameter 'prompt' well-documented. The description doesn't add any meaning beyond what the schema provides, as it doesn't elaborate on prompt formatting or constraints. With high schema coverage, the baseline score of 3 is appropriate.

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 using the Flux model.' It specifies the action (generate) and resource (image) with the specific model (Flux). However, it doesn't explicitly differentiate from the sibling tool 'run_python_code_in_sandbox,' which appears unrelated but could potentially be used for similar image generation tasks, so it lacks sibling differentiation.

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 context, prerequisites, or exclusions, nor does it reference the sibling tool. Usage is implied only by the purpose statement, with no explicit when/when-not instructions.

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

Related 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/philipp-eisen/modal-mcp-toolbox'

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