Edit an image with OpenAI
openai_edit_imageApply text-based edits to existing images, optionally using a mask to restrict changes to a specific region, and save the updated images back to disk.
Instructions
Edit or extend existing images according to a text instruction, optionally restricted to a masked region.
Source images are read from disk (only from directories listed in OPENAI_MCP_ALLOWED_DIRS) and results are written back to disk.
Args:
prompt (string, required): the edit to apply
image_paths (string[], required): 1-4 absolute paths to source images
mask_path (string): absolute path to a PNG mask; transparent pixels mark the area to replace
model (string): image model ID, defaults to OPENAI_DEFAULT_IMAGE_MODEL
n (number): 1-4 variants (default 1)
size ('auto'|'1024x1024'|'1536x1024'|'1024x1536'|'512x512'|'256x256'): default 'auto'
output_dir (string): absolute target directory
response_format ('markdown'|'json'): default 'markdown'
Returns (JSON format): { "model": string, "count": number, "images": [ { "index": number, "path": string, "bytes": number } ], "revised_prompt": string | null }
Examples:
Use when: "Replace the sky in photo.png with a sunset" -> image_paths=["/data/photo.png"], prompt="sunset sky"
Use when: combining several product shots into one scene -> image_paths=[...]
Don't use when: creating an image from scratch (use openai_generate_image)
Error Handling:
"Error: File not found" means the path does not exist
"Error: Access to ... is not permitted" means the file lives outside OPENAI_MCP_ALLOWED_DIRS
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n | No | How many variants to produce | |
| size | No | Output resolution | auto |
| model | No | Image model ID. Defaults to OPENAI_DEFAULT_IMAGE_MODEL. | |
| prompt | Yes | Instruction describing the edit to apply | |
| mask_path | No | Optional absolute path to a PNG mask; transparent areas mark the region to replace | |
| output_dir | No | Absolute directory to write the results into | |
| image_paths | Yes | Absolute paths of the source images. Must live inside an allowed directory. | |
| response_format | No | Output format: 'markdown' or 'json' | markdown |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | Yes | ||
| model | Yes | ||
| images | Yes | ||
| revised_prompt | Yes |