Skip to main content
Glama
elhombrejd

BFL MCP Server

by elhombrejd

edit_image

Modify existing images using text prompts with the FLUX.1 Kontext model. Upload an image and describe changes to transform it visually.

Instructions

Edit an existing image using FLUX.1 Kontext model based on a text prompt

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText description of how to edit the image
input_imageYesBase64 encoded input image to edit
aspect_ratioNoAspect ratio of the output image (e.g., "1:1", "16:9", "9:16")1:1
seedNoSeed for reproducible generation
safety_toleranceNoSafety tolerance level (0-6)
output_formatNoOutput image formatjpeg

Implementation Reference

  • Core handler function that executes the image editing logic by submitting a request to the BFL API endpoint '/v1/flux-kontext-pro' with the input image and prompt, then polling for the result using pollForResult.
    async editImage(request: EditImageRequest): Promise<string> {
      try {
        // Step 1: Submit editing request
        const response = await this.makeRequest('/v1/flux-kontext-pro', {
          prompt: request.prompt,
          input_image: request.input_image,
          aspect_ratio: request.aspect_ratio || '1:1',
          seed: request.seed,
          safety_tolerance: request.safety_tolerance,
          output_format: request.output_format || 'jpeg',
        });
    
        if (!response.id) {
          throw new Error('No request ID received from BFL API');
        }
    
        // Log the polling URL if provided
        if (response.polling_url) {
          console.log(`[BFL] Using polling URL: ${response.polling_url}`);
        }
    
        // Step 2: Poll for result
        const result = await this.pollForResult(response.id, response.polling_url);
    
        if (!result.result?.sample) {
          throw new Error('No image URL in response');
        }
    
        return result.result.sample;
      } catch (error) {
        throw new Error(`Image editing failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • src/index.ts:73-111 (registration)
    Tool registration in the MCP tools list, including name, description, and input schema for listTools requests.
    {
      name: 'edit_image',
      description: 'Edit an existing image using FLUX.1 Kontext model based on a text prompt',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: {
            type: 'string',
            description: 'Text description of how to edit the image',
          },
          input_image: {
            type: 'string',
            description: 'Base64 encoded input image to edit',
          },
          aspect_ratio: {
            type: 'string',
            description: 'Aspect ratio of the output image (e.g., "1:1", "16:9", "9:16")',
            default: '1:1',
          },
          seed: {
            type: 'number',
            description: 'Seed for reproducible generation',
          },
          safety_tolerance: {
            type: 'number',
            description: 'Safety tolerance level (0-6)',
            minimum: 0,
            maximum: 6,
          },
          output_format: {
            type: 'string',
            enum: ['jpeg', 'png'],
            description: 'Output image format',
            default: 'jpeg',
          },
        },
        required: ['prompt', 'input_image'],
      },
    },
  • MCP server handler for 'edit_image' tool calls, dispatching to bflClient.editImage and formatting the response.
    case 'edit_image': {
      const imageUrl = await bflClient.editImage({
        prompt: args.prompt as string,
        input_image: args.input_image as string,
        aspect_ratio: args.aspect_ratio as string | undefined,
        seed: args.seed as number | undefined,
        safety_tolerance: args.safety_tolerance as number | undefined,
        output_format: args.output_format as 'jpeg' | 'png' | undefined,
      });
    
      return {
        content: [
          {
            type: 'text',
            text: `Image edited successfully! URL: ${imageUrl}\n\nNote: The URL is valid for 10 minutes.`,
          },
        ],
      };
    }
  • TypeScript interface defining the input parameters for the editImage function.
    export interface EditImageRequest {
      prompt: string;
      input_image: string; // Base64 encoded image
      aspect_ratio?: string;
      seed?: number;
      safety_tolerance?: number;
      output_format?: 'jpeg' | 'png';
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.1 Kontext') but does not describe key behavioral traits such as whether the tool is read-only or destructive (implied as destructive since it edits images), authentication needs, rate limits, error handling, or output format details. The description is minimal and misses critical operational context for a mutation tool.

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 purpose without unnecessary words. It is front-loaded with the core action ('Edit an existing image') and includes essential context (model and prompt basis). Every part of the sentence contributes value, making it highly concise and well-structured.

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 (editing images with multiple parameters) and lack of annotations and output schema, the description is incomplete. It does not cover behavioral aspects, output details (e.g., what is returned), error cases, or usage constraints. For a mutation tool with no structured safety or output information, the description should provide more context to be adequately helpful.

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%, so the schema fully documents all 6 parameters. The description does not add any parameter-specific information beyond what the schema provides (e.g., it doesn't explain prompt formatting, image encoding details, or safety tolerance implications). Baseline score of 3 is appropriate as the schema handles parameter documentation adequately.

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 verb ('Edit') and resource ('an existing image'), specifying it uses the 'FLUX.1 Kontext model based on a text prompt'. It distinguishes from the sibling tool 'generate_image' by focusing on editing existing images rather than generating new ones, though it could be more explicit about the distinction. It's not a tautology and provides specific action details.

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

Usage Guidelines3/5

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

The description implies usage for editing images with a text prompt, but does not explicitly state when to use this tool versus alternatives like 'generate_image'. It provides context (editing existing images) but lacks explicit guidance on exclusions or prerequisites, such as when not to use it or what alternatives exist beyond the sibling tool.

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/elhombrejd/bfl_mcp'

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