I have drafted a blog post highlighting your newly published project: bg-vanish-mcp. It covers the motivation, tech stack (DirectML + U2NET), implementation details, and how to use it.
Building a Local, GPU-Accelerated Background Remover MCP Server in Python
As AI assistants like Claude and Windsurf become more integrated into our daily workflows, equipping them with local capabilities (via the Model Context Protocol or MCP) changes the game.
Today, we are announcing bg-vanish-mcp—a local-first, GPU-accelerated background removal MCP server that allows your AI assistants to isolate subjects from images instantly, completely offline, and free of charge.
Here is a look at why we built it, how it works, and how you can run it yourself.
Why Local-First & GPU-Accelerated?
While cloud-based background removal APIs exist, they come with caveats:
- Cost: Pay-per-image structures quickly add up.
- Privacy: Uploading sensitive images to third-party servers isn't always ideal.
- Speed & Latency: Sending high-resolution images back and forth over the network is slow.
bg-vanish-mcp solves this by running U2NET models locally using the rembg library. To keep processing times under a second, it leverages DirectML via ONNX Runtime, allowing hardware acceleration across NVIDIA, AMD, and Intel GPUs natively on Windows—no CUDA or complex SDK configuration required.
How It Works: The Tools
The MCP server exposes two core tools to the AI assistant:
-
remove_background(input_path, output_path, return_base64)- Purpose: Operates directly on the host file system. The AI passes a local image path, and the server output saves a clean, transparent PNG in the same directory.
-
remove_background_base64(image_base64)- Purpose: Allows direct data passing. The AI can send base64-encoded image data in-context, receive the isolated subject as a base64 string, and render it directly in the chat interface.
Under the Hood: The Code
The server is implemented in Python using the official FastMCP SDK. The core execution provider setup selectively activates the GPU:
import os
import rembg
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("bg-vanish-mcp")
# Read target environment configuration
use_gpu = os.environ.get("USE_GPU", "false").lower() in ("true", "1", "yes")
if use_gpu:
# Try GPU acceleration via CUDA or DirectML, fallback to CPU
providers = ['CUDAExecutionProvider', 'DmlExecutionProvider', 'CPUExecutionProvider']
else:
providers = ['CPUExecutionProvider']
# Initialize the ONNX session
session = rembg.new_session(providers=providers)
By requesting the DmlExecutionProvider (DirectML) before falling back to CPU, the server gains access to native DirectX 12 hardware acceleration on Windows.
Get Started in Seconds
We have published bg-vanish-mcp to PyPI so you can run it instantly without configuring local Python environments.
1. Install & Run via uvx
Make sure you have uv installed, then add this block to your Claude Desktop configuration (%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"bg-vanish-mcp": {
"command": "uvx",
"args": ["bg-vanish-mcp"],
"env": {
"USE_GPU": "true"
}
}
}
}
2. Run Locally with Pip
If you prefer standard pip:
pip install "bg-vanish-mcp[dml]"
And point your MCP client to:
bg-vanish-mcp
On first run, the server will download the U2NET ONNX model automatically, bind to your GPU, and be ready to start removing backgrounds in milliseconds.
Check Out the Code
The project is fully open source. Check out the repository, submit issues, or contribute new features:
Top comments (0)