Skip to main content
Glama

generate_image

Convert text prompts into high-quality images using the Flux Schnell model, powered by the mcp-flux-schnell MCP server for streamlined text-to-image generation.

Instructions

Generate an image from a text prompt using Flux Schnell model

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesA text description of the image you want to generate.

Implementation Reference

  • Handler for the 'generate_image' tool: validates inputs, checks env vars, calls Flux Schnell API via fetch, saves base64 image to file, returns file path.
    case "generate_image": {
      // Validate environment variables
      if (!FLUX_API_URL) {
        return {
          content: [
            {
              type: "text",
              text: "Configuration Error: FLUX_API_URL environment variable is not set",
            },
          ],
        };
      }
      if (!FLUX_API_TOKEN) {
        return {
          content: [
            {
              type: "text",
              text: "Configuration Error: FLUX_API_TOKEN environment variable is not set",
            },
          ],
        };
      }
    
      // Validate input parameters
      const validationResult = generateImageSchema.safeParse(
        request.params.arguments
      );
      if (!validationResult.success) {
        return {
          content: [
            {
              type: "text",
              text: `Input Error: ${validationResult.error.message}`,
            },
          ],
        };
      }
    
      const { prompt } = validationResult.data;
      const timestamp = new Date().getTime();
      const filename = `flux-${timestamp}.png`;
      const directory = WORKING_DIR;
      const filepath = join(directory, filename);
    
      // Check if directory exists and create it if it doesn't
      if (!existsSync(directory)) {
        try {
          await mkdir(directory, { recursive: true });
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Directory Error: Failed to create directory ${directory}: ${error instanceof Error ? error.message : 'Unknown error'}`,
              },
            ],
          };
        }
      }
    
      try {
        // Call Flux Schnell API
        const response = await fetch(FLUX_API_URL, {
          method: "POST",
          headers: {
            Authorization: `Bearer ${FLUX_API_TOKEN}`,
            "Content-Type": "application/json",
          },
          body: JSON.stringify({ prompt }),
        });
    
        if (!response.ok) {
          const errorText = await response.text();
          return {
            content: [
              {
                type: "text",
                text: `API Error: Flux API returned status ${response.status}: ${errorText}`,
              },
            ],
          };
        }
    
        const result = await response.json();
        const base64Data = result.image.replace(/^data:image\/png;base64,/, "");
        await writeFile(filepath, Buffer.from(base64Data, "base64"));
    
        return {
          content: [
            {
              type: "text",
              text: `Image saved successfully:\nFilename: ${filename}\nPath: ${filepath}`,
            },
          ],
        };
      } catch (error: unknown) {
        const errorMessage =
          error instanceof Error ? error.message : "An unknown error occurred";
        return {
          content: [
            {
              type: "text",
              text: `Operation Error: Failed to generate or save image: ${errorMessage}`,
            },
          ],
        };
      }
    }
  • Zod schema for validating 'generate_image' tool input: requires a prompt string between 1-2048 chars.
    const generateImageSchema = z.object({
      prompt: z.string().min(1).max(2048),
    });
  • src/index.ts:49-70 (registration)
    Registration of 'generate_image' tool in ListToolsRequestSchema handler, including name, description, and inputSchema.
    return {
      tools: [
        {
          name: "generate_image",
          description:
            "Generate an image from a text prompt using Flux Schnell model",
          inputSchema: {
            type: "object",
            properties: {
              prompt: {
                type: "string",
                minLength: 1,
                maxLength: 2048,
                description:
                  "A text description of the image you want to generate.",
              },
            },
            required: ["prompt"],
          },
        },
      ],
    };
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 mentions the model ('Flux Schnell') but fails to describe key traits like whether this is a read-only or mutative operation, potential rate limits, authentication needs, output format, or error handling. This leaves significant gaps for an AI agent to understand how to invoke it safely and effectively.

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 a single, efficient sentence that directly states the tool's function without any redundant or extraneous information. It is front-loaded and appropriately sized for a simple tool, making it easy for an AI agent to parse quickly.

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 lack of annotations and output schema, the description is incomplete for a tool that performs image generation. It does not cover behavioral aspects like mutation risks, rate limits, or output details (e.g., image format, size), which are crucial for an AI agent to use the tool correctly in various contexts.

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 'prompt' parameter well-documented in the schema itself. The description adds minimal value beyond the schema by implying the prompt is for image generation, but it does not provide additional context like prompt formatting tips or model-specific constraints. This meets the baseline for high schema coverage.

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 from a text prompt using Flux Schnell model.' It specifies the verb ('generate'), resource ('image'), and method ('using Flux Schnell model'), which is specific and unambiguous. However, since there are no sibling tools, it cannot demonstrate differentiation from alternatives, preventing a perfect 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, prerequisites, or constraints. It merely states what the tool does without indicating appropriate contexts or exclusions, such as when other image generation models might be preferred or if there are usage limits.

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

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