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
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Text description of how to edit the image | |
| input_image | Yes | Base64 encoded input image to edit | |
| aspect_ratio | No | Aspect ratio of the output image (e.g., "1:1", "16:9", "9:16") | 1:1 |
| seed | No | Seed for reproducible generation | |
| safety_tolerance | No | Safety tolerance level (0-6) | |
| output_format | No | Output image format | jpeg |
Implementation Reference
- src/bfl-client.ts:134-166 (handler)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'], }, },
- src/index.ts:158-176 (handler)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.`, }, ], }; }
- src/types.ts:14-20 (schema)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';