Skip to main content
Glama

FLUX_1-schnell-infer

Generate images from text prompts using the FLUX.1 model. Specify dimensions, inference steps, and seed parameters for image creation.

Instructions

Call the FLUX.1-schnell endpoint /infer

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesPrompt
seedNoSeed
randomize_seedNoRandomize seed
widthNoWidth
heightNoHeight
num_inference_stepsNoNumber of inference steps

Implementation Reference

  • Core handler function that executes the Gradio client.submit to the /infer endpoint of FLUX.1-schnell space, processes events, progress, and converts results to MCP format.
    async handleToolCall(
      parameters: Record<string, unknown>,
      progressToken: string | undefined,
      server: Server,
    ): Promise<CallToolResult> {
      const events = [];
      try {
        let result = null;
        const submission: AsyncIterable<GradioEvent> = this.client.submit(
          this.endpointPath.endpoint,
          parameters,
        ) as AsyncIterable<GradioEvent>;
        const progressNotifier = createProgressNotifier(server);
        for await (const msg of submission) {
          if (config.debug) events.push(msg);
          if (msg.type === "data") {
            if (Array.isArray(msg.data)) {
              const hasContent = msg.data.some(
                (item: unknown) => typeof item !== "object",
              );
    
              if (hasContent) result = msg.data;
              if (null === result) result = msg.data;
            }
          } else if (msg.type === "status") {
            if (msg.stage === "error") {
              throw new Error(`Gradio error: ${msg.message || "Unknown error"}`);
            }
            if (progressToken) await progressNotifier.notify(msg, progressToken);
          }
        }
    
        if (!result) {
          throw new Error("No data received from endpoint");
        }
    
        return await this.convertPredictResults(
          this.endpoint.returns,
          result,
          this.endpointPath,
        );
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        throw new Error(`Error calling endpoint: ${errorMessage}`);
      } finally {
        if (config.debug && events.length > 0) {
          await fs.writeFile(
            `${this.mcpToolName}_status_${crypto
              .randomUUID()
              .substring(0, 5)}.json`,
            JSON.stringify(events, null, 2),
          );
        }
      }
    }
  • Entry point for tool execution, processes input arguments (handles files), normalizes progress token, and delegates to handleToolCall.
    async call(
      request: CallToolRequest,
      server: Server,
    ): Promise<CallToolResult> {
      const progressToken = request.params._meta?.progressToken as
        | string
        | number
        | undefined;
    
      const parameters = request.params.arguments as Record<string, unknown>;
    
      // Get the endpoint parameters to check against
      const endpointParams = this.endpoint.parameters;
    
      // Process each parameter, applying handle_file for file inputs
      for (const [key, value] of Object.entries(parameters)) {
        const param = endpointParams.find(
          (p) => p.parameter_name === key || p.label === key,
        );
        if (param && isFileParameter(param) && typeof value === "string") {
          const file = await this.validatePath(value);
          parameters[key] = handle_file(file);
        }
      }
    
      const normalizedToken =
        typeof progressToken === "number"
          ? progressToken.toString()
          : progressToken;
    
      return this.handleToolCall(parameters, normalizedToken, server);
    }
  • src/index.ts:56-71 (registration)
    Creates EndpointWrapper instances for each configured spacePath (including default 'black-forest-labs/FLUX.1-schnell'), sets mcpToolName to 'FLUX_1-schnell-infer', and stores in endpoints map used for registration.
    for (const spacePath of config.spacePaths) {
      try {
        const endpoint = await EndpointWrapper.createEndpoint(
          spacePath,
          workingDir,
        );
        endpoints.set(endpoint.toolDefinition().name, endpoint);
      } catch (e) {
        if (e instanceof Error) {
          console.error(`Error loading ${spacePath}: ${e.message}`);
        } else {
          throw e;
        }
        continue;
      }
    }
  • src/index.ts:77-115 (registration)
    Registers all endpoint tools (including FLUX_1-schnell-infer) in the MCP listTools handler by mapping endpoints to their toolDefinition().
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: AVAILABLE_FILES,
            description:
              "A list of available file and resources. " +
              "If the User requests things like 'most recent image' or 'the audio' use " +
              "this tool to identify the intended resource." +
              "This tool returns 'resource uri', 'name', 'size', 'last modified'  and 'mime type' in a markdown table",
            inputSchema: {
              type: "object",
              properties: {},
            },
          },
          {
            name: SEARCH_FOR_SPACE,
            description:
              "Use semantic search to find an endpoint on the `Hugging Face Spaces` service. The search term will usually " +
              "be 3-7 words describing a task or activity the Person is trying to accomplish. The results are returned in a markdown table. " +
              "Present all results to the Person. Await specific guidance from the Person before making further Tool calls.",
            inputSchema: {
              type: "object",
              properties: {
                query: {
                  type: "string",
                  // TODO description assumes  user is using claude desktop which has knowledge of HF Spaces.
                  // consider updating for not CLAUDE_DESKTOP mode. 3.7 sys prompt refers to Human as Person
                  description: "The semantic search term to use.",
                },
              },
            },
          },
          ...Array.from(endpoints.values()).map((endpoint) =>
            endpoint.toolDefinition(),
          ),
        ],
      };
    });
  • src/index.ts:167-188 (registration)
    Registers the callTool handler that dispatches calls to the specific EndpointWrapper.call() based on tool name.
      const endpoint = endpoints.get(request.params.name);
    
      if (!endpoint) {
        throw new Error(`Unknown tool: ${request.params.name}`);
      }
      try {
        return await endpoint.call(request, server);
      } catch (error) {
        if (error instanceof Error) {
          return {
            content: [
              {
                type: `text`,
                text: `mcp-hfspace error: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    });
  • Generates the MCP inputSchema for the tool from the Gradio ApiEndpoint parameters (used by toolDefinition()).
    export function convertApiToSchema(endpoint: ApiEndpoint) {
      const properties: { [key: string]: ParameterSchema } = {};
      const required: string[] = [];
      let propertyCounter = 1;
      const unnamedParameters: Record<string, number> = {};
    
      endpoint.parameters.forEach((param: ApiParameter, index: number) => {
        // Get property name from parameter_name, label, or generate one
        const propertyName =
          param.parameter_name ||
          param.label ||
          `Unnamed Parameter ${propertyCounter++}`;
        if (!param.parameter_name) {
          unnamedParameters[propertyName] = index;
        }
        // Convert parameter using existing function
        properties[propertyName] = convertParameter(param);
    
        // Add to required if no default value
        if (!param.parameter_has_default) {
          required.push(propertyName);
        }
      });
    
      return {
        type: "object",
        properties,
        required,
      };
    }
  • Defines the default HuggingFace space path 'black-forest-labs/FLUX.1-schnell' used to create the FLUX_1-schnell-infer tool.
      spacePaths: (() => {
        const filtered = argv._.filter((arg) => arg.toString().trim().length > 0);
        return filtered.length > 0
          ? filtered
          : ["black-forest-labs/FLUX.1-schnell"];
      })(),
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed12 schema fields changedv1.0.0
    • changedInput schema / properties / height / description
      Previous value: -"numeric value between 256 and 2048"New value: +"Height"
    • removedInput schema / properties / height / maximum
      Removed value: -2048
    • removedInput schema / properties / height / minimum
      Removed value: -256
    • changedInput schema / properties / num_inference_steps / description
      Previous value: -"numeric value between 1 and 50"New value: +"Number of inference steps"
    • removedInput schema / properties / num_inference_steps / maximum
      Removed value: -50
    • removedInput schema / properties / num_inference_steps / minimum
      Removed value: -1
    • changedInput schema / properties / seed / description
      Previous value: -"numeric value between 0 and 2147483647"New value: +"Seed"
    • removedInput schema / properties / seed / maximum
      Removed value: -2147483647
    • removedInput schema / properties / seed / minimum
      Removed value: -0
    • changedInput schema / properties / width / description
      Previous value: -"numeric value between 256 and 2048"New value: +"Width"
    • removedInput schema / properties / width / maximum
      Removed value: -2048
    • removedInput schema / properties / width / minimum
      Removed value: -256
  2. First observed

TDQS

C2.2/5.0
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 only states the endpoint call without explaining what the tool does (e.g., image generation), its effects (e.g., creates an image file), performance traits, or any constraints like rate limits or authentication needs, resulting in insufficient transparency for a tool with multiple parameters.

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, concise sentence that directly states the action. It is front-loaded with no unnecessary words, making it efficient. However, it lacks depth, which is a content issue rather than a structural one, so it scores well for conciseness.

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 with 6 parameters and no output schema, the description is incomplete. It fails to explain the tool's purpose, behavior, or output, leaving significant gaps. Without annotations or a clear context, it does not provide enough information for effective use, especially compared to sibling tools.

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?

Schema description coverage is 100%, providing basic descriptions for all parameters. The description adds no additional meaning beyond the schema, such as explaining parameter interactions or use cases. However, since the schema is fully documented, the baseline score of 3 is appropriate as the description does not compensate but also does not detract.

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

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Call the FLUX.1-schnell endpoint /infer' restates the tool name and title without specifying what the tool does. It mentions an endpoint but lacks a clear verb and resource, such as generating images or processing prompts, making the purpose vague and not distinguishing it from sibling tools like 'available-files' or 'search-spaces'.

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

Usage Guidelines1/5

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

No guidance is provided on when to use this tool versus alternatives. The description does not mention any context, prerequisites, or exclusions, leaving the agent with no information on appropriate usage scenarios or how it differs from sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools