AI assistants are now where a lot of image work starts. You ask Claude Code to prepare product photos for a store, or Cursor to generate assets for an app, and the next step is always the same: the background has to go. A background removal MCP server gives the assistant that tool. This tutorial installs our open source server in one command, runs a real session in Claude Code, and shows how the tool works if you want to build your own.
There is also a deadline. The remove.bg self-service API stops on December 1, 2026. MCP connectors that call it with a remove.bg key, such as the Composio and Zapier remove.bg integrations, stop with it. If your assistant workflows use one, this server is a direct replacement. For code that calls remove.bg directly, see the remove.bg API migration guide.
Want to try it? Get a free key for the Background Removal API.
What the server gives your assistant
MCP (Model Context Protocol) is the standard that Claude Code, Claude Desktop, Cursor and many other assistants use to call external tools. The server exposes six tools. Three of them edit backgrounds:
-
remove_background: transparent PNG cutout, saved asname_nobg.png -
color_background: subject on a solid color, white by default, saved asname_color.png -
blur_background: subject sharp, background blurred, saved asname_blur.png
Each tool takes a local path or a public image URL, and an optional output_path. The other three read text from images and PDFs with the OCR Wizard API and check images before publishing with the NSFW Detect API. The code is on GitHub under the MIT license.
Get an API key
- Create a free account on RapidAPI.
- Open the Background Removal API and subscribe to the free plan (same for OCR Wizard and NSFW Detect if you want those tools).
- Copy your key from the Endpoints tab: it is the value of the
X-RapidAPI-Keyheader. The same key works for all three APIs.
The server reads the key from the RAPIDAPI_KEY environment variable. It never writes it to disk and never returns it to the assistant.
Install in Claude Code, Claude Desktop or Cursor
You need uv, the Python package runner. uvx downloads the server from GitHub and runs it. In Claude Code, one command:
claude mcp add ai-engine -e RAPIDAPI_KEY=your_key -- \
uvx --from "git+https://github.com/ai-engine-dev/api-examples#subdirectory=mcp-server" ai-engine-mcp
In Claude Desktop, add this block to claude_desktop_config.json (Settings, Developer, Edit Config) and restart. Cursor uses the same block in ~/.cursor/mcp.json:
{
"mcpServers": {
"ai-engine": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/ai-engine-dev/api-examples#subdirectory=mcp-server",
"ai-engine-mcp"
],
"env": { "RAPIDAPI_KEY": "your_key" }
}
}
}
Replace your_key with your RapidAPI key. In Claude Code, /mcp lists the server and its six tools.
A real session: product photos for a store
We tested the server installed from GitHub in Claude Code, on a folder with three product photos and a portrait, all public domain photos from Wikimedia Commons. One prompt:
> Remove the background of every photo in ./products, put each one on a white
background for my online store and save them in ./store. Then blur the
background of portrait.jpg for my about page.
The assistant listed the folder, created ./store and sent the four tool calls at once (paths shortened):
ai-engine - color_background(image: "products/handbag.jpg", color: "#FFFFFF", output_path: "store/handbag.png")
ai-engine - color_background(image: "products/runner.jpg", color: "#FFFFFF", output_path: "store/runner.png")
ai-engine - color_background(image: "products/sneakers.jpg", color: "#FFFFFF", output_path: "store/sneakers.png")
ai-engine - blur_background(image: "portrait.jpg", output_path: "portrait_blur.png")
All three product photos are now on a white background in ./store, and the
portrait has a blurred background. The originals are untouched.
- store/handbag.png (850x900)
- store/runner.png (1280x1067)
- store/sneakers.png (1280x1707)
- portrait_blur.png (1280x853), using the default blur strength of 15
The whole session took 39 seconds, including the assistant opening each result to check it. It picked color_background on its own, chose the output names from the prompt and kept the originals.
A second session with three more prompts worked as written:
-
"Check that portrait.jpg is safe to publish, then cut it out as a transparent PNG" called
check_nsfw(safe, no labels), thenremove_background. -
"Put runner.jpg on our brand color #0F172A" passed the color straight to
color_background. - "Center each product in ./store on a 1200x1200 white square" cut the products out again and scaled each one into a 1000 pixel box with Pillow, so every product is the same size in a catalog grid.
Test the server without an assistant
To check your setup, or to call the tools from your own agent, use the MCP Python client. Save this as test_server.py:
import asyncio
import os
import sys
import time
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
SERVER = StdioServerParameters(
command="uvx",
args=["--from", "git+https://github.com/ai-engine-dev/api-examples#subdirectory=mcp-server",
"ai-engine-mcp"],
env={**os.environ}, # passes RAPIDAPI_KEY to the server
)
async def main(image):
async with stdio_client(SERVER) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = await session.list_tools()
print("tools:", ", ".join(t.name for t in tools.tools))
start = time.time()
result = await session.call_tool("remove_background", {"image": image})
print(result.content[0].text)
print(f"{time.time() - start:.1f} s")
asyncio.run(main(sys.argv[1]))
export RAPIDAPI_KEY=your_key
uvx --with mcp python test_server.py runner.jpg
tools: remove_background, color_background, blur_background, extract_text, extract_pdf_text, check_nsfw
{
"saved_to": "/home/me/photos/runner_nobg.png",
"image_url": "https://images.ai-engine.net/background-removal-ai/1716d390-0dc9-4771-9aad-f6459d2952cc.png",
"width": 1280,
"height": 1067
}
6.0 s
The result is an RGBA PNG with a real alpha channel. The assistant only receives this small JSON, not the image, which keeps its context short on a whole folder.
How the tool works: build your own
An MCP tool is a Python function with a decorator. Its docstring is what the assistant reads to decide when to call it. This standalone server has one tool:
import os
from pathlib import Path
import requests
from mcp.server import MCPServer
from mcp.server.mcpserver.exceptions import ToolError
HOST = "background-removal-ai.p.rapidapi.com"
mcp = MCPServer(name="background-removal")
@mcp.tool()
def remove_background(image: str) -> dict:
"""Remove the background of a photo and save a transparent PNG next to it.
Args:
image: Path of a local image file.
"""
key = os.environ.get("RAPIDAPI_KEY")
if not key:
raise ToolError("Set the RAPIDAPI_KEY environment variable.")
path = Path(image).expanduser().resolve()
if not path.is_file():
raise ToolError(f"File not found: {path}")
with open(path, "rb") as f:
r = requests.post(f"https://{HOST}/remove-background",
headers={"x-rapidapi-host": HOST, "x-rapidapi-key": key},
files={"image": f}, timeout=120)
if r.status_code != 200:
raise ToolError(f"HTTP {r.status_code}: {r.text[:200]}")
data = r.json()
out = path.with_name(f"{path.stem}_nobg.png")
out.write_bytes(requests.get(data["image_url"], timeout=120).content)
return {"saved_to": str(out), "width": data["width"], "height": data["height"]}
if __name__ == "__main__":
mcp.run()
-
Errors are raised as
ToolErrorwith a plain message, so the assistant can fix the problem itself, for example a wrong path. - The tool saves the file and returns its path, not image bytes.
- The key comes from the environment, so the config can be shared without the key.
Share the setup with your team
Commit a .mcp.json at the project root that references the variable instead of the key. Claude Code expands ${RAPIDAPI_KEY} from each person's environment:
{
"mcpServers": {
"ai-engine": {
"command": "uvx",
"args": ["--from", "git+https://github.com/ai-engine-dev/api-examples#subdirectory=mcp-server", "ai-engine-mcp"],
"env": { "RAPIDAPI_KEY": "${RAPIDAPI_KEY}" }
}
}
}
Never commit a config that contains the key itself. If a key leaks, regenerate it in your RapidAPI dashboard.
Replacing a remove.bg MCP connector
Remove the old server, add this one, keep your prompts:
- Remove background, transparent output:
remove_background -
bg_color(white or brand color):color_backgroundwith#RRGGBBorR,G,B,A - Image URL as input: any tool, pass the URL as
image - Portrait blur:
blur_backgroundwithblur_radius
The output is always a full resolution PNG. For a crop, a resize or a JPG, ask the assistant to do it on the saved file.
Production tips
- Use the assistant for tasks, scripts for catalogs. For thousands of SKUs every night, call the API from a script with retries, as in the background removal at scale guide.
- Name the output folder in the prompt for clean paths.
- Ask for a consistent frame with "center each product on a 1200x1200 white square".
-
Check user content first: chain
check_nsfwbefore any edit or upload.
Full tutorial with images: Background Removal MCP Server on ai-engine.net.
Get a free key on the Background Removal API page, run the
claude mcp addcommand, and ask your assistant to clean up a folder of your own photos.
Test photos (CC0, Wikimedia Commons): sneakers, runners, handbag, portrait.

Top comments (0)