edit_image
Modify images using text prompts with the FLUX.1 Kontext model, adjusting aspect ratios, safety levels, and output formats for precise visual edits.
Instructions
Edit an existing image using FLUX.1 Kontext model based on a text prompt
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aspect_ratio | No | Aspect ratio of the output image (e.g., "1:1", "16:9", "9:16") | 1:1 |
| input_image | Yes | Base64 encoded input image to edit | |
| output_format | No | Output image format | jpeg |
| prompt | Yes | Text description of how to edit the image | |
| safety_tolerance | No | Safety tolerance level (0-6) | |
| seed | No | Seed for reproducible generation |
Implementation Reference
- src/index.ts:158-176 (handler)MCP tool handler for 'edit_image': parses arguments, calls bflClient.editImage, and returns the generated image URL.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/index.ts:73-111 (registration)Registration of the 'edit_image' tool in the tools list, including name, description, and input schema for MCP ListTools.{ 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/types.ts:14-20 (schema)TypeScript interface defining the EditImageRequest schema used by the editImage method.export interface EditImageRequest { prompt: string; input_image: string; // Base64 encoded image aspect_ratio?: string; seed?: number; safety_tolerance?: number; output_format?: 'jpeg' | 'png';
- src/bfl-client.ts:134-166 (helper)Core implementation of image editing: submits request to BFL API endpoint '/v1/flux-kontext-pro' with input_image and polls for the result URL using shared polling logic.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'}`); } }