Skip to main content
Glama

inpaint_image

Edit specific image regions by regenerating masked areas based on text prompts to modify or remove objects.

Instructions

Edit specific regions of an image using a mask. White areas in the mask will be regenerated based on the prompt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlYesURL of the source image (use upload_file for local images)
mask_urlYesURL of the mask image (white=edit, black=keep). Use upload_file for local masks.
promptYesWhat to generate in the masked area (e.g., 'a red sports car', 'green grass')
modelNoInpainting model. Options: fal-ai/flux-kontext-lora/inpaint, fal-ai/flux-krea-lora/inpaintingfal-ai/flux-kontext-lora/inpaint
negative_promptNoWhat to avoid in the generated area
seedNoSeed for reproducible results

Implementation Reference

  • The main handler function that executes the inpaint_image tool: resolves model ID, prepares Fal.ai arguments, executes via queue_strategy with timeout handling, processes response, extracts output image URL, and formats success/error messages.
    async def handle_inpaint_image(
        arguments: Dict[str, Any],
        registry: ModelRegistry,
        queue_strategy: QueueStrategy,
    ) -> List[TextContent]:
        """Handle the inpaint_image tool for masked region editing."""
        model_input = arguments.get("model", "fal-ai/flux-kontext-lora/inpaint")
        try:
            model_id = await registry.resolve_model_id(model_input)
        except ValueError as e:
            return [
                TextContent(
                    type="text",
                    text=f"❌ {e}. Use list_models to see available options.",
                )
            ]
    
        fal_args: Dict[str, Any] = {
            "image_url": arguments["image_url"],
            "mask_url": arguments["mask_url"],
            "prompt": arguments["prompt"],
        }
    
        # Add optional parameters
        if "negative_prompt" in arguments:
            fal_args["negative_prompt"] = arguments["negative_prompt"]
        if "seed" in arguments:
            fal_args["seed"] = arguments["seed"]
    
        logger.info("Starting inpainting with %s: '%s'", model_id, arguments["prompt"][:50])
    
        try:
            result = await asyncio.wait_for(
                queue_strategy.execute_fast(model_id, fal_args),
                timeout=90,
            )
        except asyncio.TimeoutError:
            logger.error("Inpainting timed out for %s", model_id)
            return [
                TextContent(
                    type="text",
                    text="❌ Inpainting timed out after 90 seconds. Please try again.",
                )
            ]
        except Exception as e:
            logger.exception("Inpainting failed: %s", e)
            return [
                TextContent(
                    type="text",
                    text=f"❌ Inpainting failed: {e}",
                )
            ]
    
        # Check for error in response
        if "error" in result:
            error_msg = result.get("error", "Unknown error")
            logger.error("Inpainting failed for %s: %s", model_id, error_msg)
            return [
                TextContent(
                    type="text",
                    text=f"❌ Inpainting failed: {error_msg}",
                )
            ]
    
        # Extract the result image URL
        images = result.get("images", [])
        if images:
            output_url = images[0].get("url") if isinstance(images[0], dict) else images[0]
        else:
            image_data = result.get("image", {})
            if isinstance(image_data, dict):
                output_url = image_data.get("url")
            else:
                output_url = result.get("image_url")
    
        if not output_url:
            logger.warning("Inpainting returned no image. Result: %s", result)
            return [
                TextContent(
                    type="text",
                    text="❌ Inpainting completed but no image was returned.",
                )
            ]
    
        response = "🖌️ Inpainting completed!\n\n"
        response += f"**Prompt**: {arguments['prompt']}\n\n"
        response += f"**Result**: {output_url}"
        return [TextContent(type="text", text=response)]
  • Input schema and Tool definition for inpaint_image, defining parameters (image_url, mask_url, prompt, model, etc.) with descriptions, defaults, and required fields for MCP validation.
    Tool(
        name="inpaint_image",
        description="Edit specific regions of an image using a mask. White areas in the mask will be regenerated based on the prompt.",
        inputSchema={
            "type": "object",
            "properties": {
                "image_url": {
                    "type": "string",
                    "description": "URL of the source image (use upload_file for local images)",
                },
                "mask_url": {
                    "type": "string",
                    "description": "URL of the mask image (white=edit, black=keep). Use upload_file for local masks.",
                },
                "prompt": {
                    "type": "string",
                    "description": "What to generate in the masked area (e.g., 'a red sports car', 'green grass')",
                },
                "model": {
                    "type": "string",
                    "default": "fal-ai/flux-kontext-lora/inpaint",
                    "description": "Inpainting model. Options: fal-ai/flux-kontext-lora/inpaint, fal-ai/flux-krea-lora/inpainting",
                },
                "negative_prompt": {
                    "type": "string",
                    "description": "What to avoid in the generated area",
                },
                "seed": {
                    "type": "integer",
                    "description": "Seed for reproducible results",
                },
            },
            "required": ["image_url", "mask_url", "prompt"],
        },
    ),
  • TOOL_HANDLERS dictionary registers the 'inpaint_image' tool name to its handler function handle_inpaint_image, enabling dispatch in the call_tool method.
    TOOL_HANDLERS = {
        # Utility tools (no queue needed)
        "list_models": handle_list_models,
        "recommend_model": handle_recommend_model,
        "get_pricing": handle_get_pricing,
        "get_usage": handle_get_usage,
        "upload_file": handle_upload_file,
        # Image generation tools
        "generate_image": handle_generate_image,
        "generate_image_structured": handle_generate_image_structured,
        "generate_image_from_image": handle_generate_image_from_image,
        # Image editing tools
        "remove_background": handle_remove_background,
        "upscale_image": handle_upscale_image,
        "edit_image": handle_edit_image,
        "inpaint_image": handle_inpaint_image,
        "resize_image": handle_resize_image,
        "compose_images": handle_compose_images,
        # Video tools
        "generate_video": handle_generate_video,
        "generate_video_from_image": handle_generate_video_from_image,
        "generate_video_from_video": handle_generate_video_from_video,
        # Audio tools
        "generate_music": handle_generate_music,
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but lacks critical behavioral details. It doesn't disclose whether this is a read-only or mutation operation, potential rate limits, authentication requirements, or what happens to non-masked areas. The description only covers basic functionality without operational context.

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?

Perfectly concise with two sentences that each earn their place. The first sentence states the core purpose, the second explains mask behavior and prompt usage. No wasted words, well-structured, and front-loaded with essential information.

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?

For a 6-parameter mutation tool with no annotations and no output schema, the description is incomplete. It covers basic functionality but lacks information about return values, error conditions, side effects, or how this tool differs behaviorally from similar editing tools in the sibling set.

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 already documents all 6 parameters thoroughly. The description adds minimal value beyond the schema by briefly explaining mask logic ('white=edit, black=keep') and giving prompt examples, but doesn't provide significant additional semantic context.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verb ('Edit') and resource ('specific regions of an image using a mask'), and distinguishes it from siblings by focusing on inpainting rather than generation, composition, or other edits. It precisely explains the white/black mask logic.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus alternatives like 'edit_image' or 'remove_background'. The description mentions using 'upload_file for local images' but doesn't clarify tool selection context or prerequisites beyond basic parameter usage.

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/raveenb/fal-mcp-server'

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