Skip to main content
Glama
yunwoong7
by yunwoong7

background_removal

Remove image backgrounds automatically to isolate subjects. Input an image path and receive a cleaned image file, enhancing focus on the main content for editing or design purposes.

Instructions

Remove the background of an image automatically.

Args:
    image_path: File path of the original image
    ctx: MCP context
    
Returns:
    Dict: Dictionary containing the file path of the image with the background removed

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_pathYes

Implementation Reference

  • The handler function that implements the background removal logic: reads input image, encodes to base64, sends to Bedrock API with BACKGROUND_REMOVAL task, saves output image, returns path and message.
    async def background_removal(
            image_path: str,
            output_path: str = None,
            ctx: Context = None,
    ) -> Dict[str, Any]:
        """
        Remove the background of an image automatically.
        
        Args:
            image_path: File path of the original image, Please use the actual local file path where the image is stored.
            output_path: Absolute path to save the image
            ctx: MCP context
            
        Returns:
            Dict: Dictionary containing the file path of the image with the background removed
        """
        try:
            # Read image file and encode to base64
            with open(image_path, "rb") as image_file:
                input_image = base64.b64encode(image_file.read()).decode('utf8')
    
            body = json.dumps({
                "taskType": "BACKGROUND_REMOVAL",
                "backgroundRemovalParams": {
                    "image": input_image,
                }
            })
    
            # Generate image
            image_bytes = generate_image(body)
    
            # Save image
            image_info = save_image(image_bytes, output_path=output_path)
    
            # Generate result
            result = {
                "image_path": image_info["image_path"],
                "message": f"Background removed successfully. Saved location: {image_info['image_path']}"
            }
    
            return result
    
        except Exception as e:
            raise McpError(f"Error occurred while removing background: {str(e)}")
  • Registers the background_removal tool with the FastMCP server instance.
    mcp.add_tool(background_removal)

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related 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/yunwoong7/aws-nova-canvas-mcp'

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