remove-background
A Model Context Protocol server for removing backgrounds from images using AI-powered segmentation models.
README
MCP Remove Background Server
A Model Context Protocol (MCP) server for removing backgrounds from images using AI-powered segmentation models.
Features
- Background Removal: Remove backgrounds from images using AI-powered segmentation
- Multiple model options optimized for different image types
- Outputs PNG with full alpha transparency
- Fast flood-fill algorithm for simple backgrounds (optional)
- Model Catalog: Access comprehensive information about all available background removal models
Supported Models
| Model | Size | Best For | Quality |
|---|---|---|---|
u2net |
176MB | General purpose (default) | Good |
u2netp |
4MB | Lightweight/mobile | Moderate |
silueta |
43MB | General, smaller footprint | Good |
isnet-general-use |
176MB | General, newer | Very Good |
isnet-anime |
176MB | Anime/illustrations | Excellent for art |
birefnet-general |
400MB | Best quality | Excellent |
birefnet-general-lite |
100MB | Balanced | Very Good |
sam |
400MB | Segment Anything | Excellent |
Installation
Option 1: Install with pipx (Recommended for CLI usage)
# Install directly from the repository
pipx install git+https://github.com/your-username/MCP-remove-background.git
# Or install from local directory
cd MCP-remove-background
pipx install .
# Run the server
mcp-remove-background
Option 2: Install with Poetry (Recommended for development)
# Clone the repository
git clone <repository-url>
cd MCP-remove-background
# Install dependencies with Poetry
just setup
# Run the server
poetry run mcp-remove-background
# Or
poetry run python -m MCP_remove_background.server
Option 3: Install with pip
# Install from the repository
pip install git+https://github.com/your-username/MCP-remove-background.git
# Or install from local directory
pip install .
# Run the server
mcp-remove-background
Usage
Running the Server
# If installed with pipx or pip
mcp-remove-background
# If using Poetry (development)
poetry run mcp-remove-background
# Alternative: run as Python module
poetry run python -m MCP_remove_background.server
# With FastMCP CLI (more options)
poetry run fastmcp run MCP_remove_background/server.py --transport http --port 8000
CLI Options
When using the fastmcp run command, you have additional options:
| Option | Description |
|---|---|
--transport, -t |
Transport protocol: stdio (default), http, sse, streamable-http |
--host |
Host to bind to (default: 127.0.0.1) |
--port, -p |
Port for HTTP/SSE transport (default: 8000) |
--log-level, -l |
Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL |
--no-banner |
Don't show the server banner |
MCP Client Configuration
To use this MCP server with an AI agent, add the following configuration to your MCP client.
Claude Desktop (pipx installation)
If you installed with pipx, add to your Claude Desktop configuration file (~/.config/claude/claude_desktop_config.json on Linux, ~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"remove-background": {
"command": "mcp-remove-background"
}
}
}
Claude Desktop (Poetry installation)
If you're using Poetry for development:
{
"mcpServers": {
"remove-background": {
"command": "poetry",
"args": ["run", "mcp-remove-background"],
"cwd": "/path/to/MCP-remove-background"
}
}
}
Cline / Roo Code
Add to your VS Code settings or Cline MCP configuration:
{
"mcpServers": {
"remove-background": {
"command": "mcp-remove-background"
}
}
}
Generic MCP Client (Copy-Paste Ready)
For pipx/pip installation:
{
"remove-background": {
"command": "mcp-remove-background"
}
}
For Poetry installation:
{
"remove-background": {
"command": "poetry",
"args": ["run", "mcp-remove-background"],
"cwd": "/path/to/MCP-remove-background"
}
}
Configuration Options:
| Field | Description |
|---|---|
command |
The command to run (poetry for Poetry-managed projects) |
args |
Command arguments to start the MCP server |
cwd |
Working directory - set to your MCP-remove-background installation path |
Important: Replace /path/to/MCP-remove-background with the actual path to your installation.
Tools
remove_background
Remove the background from an image, replacing it with transparency.
Parameters:
image_path(required): Path to the image file to processoutput_path(optional): Path for the output PNG file (auto-generated if not specified)model(optional): Background removal model (default: "u2net")alpha_matting(optional): Enable alpha matting for smoother edges (default: false)try_floodfill_first(optional): Try fast flood-fill before ML (default: true)
Returns:
success: Whether background removal succeededinput_path: Path to the input fileoutput_path: Path to the output PNG file with transparencyfile_size_bytes: Size of the output file in bytesmethod_used: "floodfill" or model namemodel_used: The model that was configurederror: Error message if removal failed
Example:
result = await remove_background(
image_path="/path/to/image.png",
model="isnet-anime"
)
if result["success"]:
print(f"Transparent image saved to: {result['output_path']}")
list_background_models
List all available background removal models with their descriptions.
Parameters: None
Returns:
models: List of available models with id, name, description, and sizetotal_count: Number of available modelsdefault_model: The default model used when not specifiedusage_hint: How to use the model parameter
Example Response:
{
"models": [
{
"id": "u2net",
"name": "U2-Net",
"description": "General purpose background removal model",
"size": "176MB"
},
...
],
"total_count": 8,
"default_model": "u2net",
"usage_hint": "Pass model='model_id' to remove_background tool"
}
Development
Setup
# Initialize the development environment
just setup
Running Tests
# Run all tests with coverage
just test
# Run specific test file
poetry run pytest tests/unit/test_constants.py -v
Code Quality
# Run formatting
just format
# Run all pre-commit hooks (includes formatting, linting, type-checking)
just validate
# Run type checking only
just typecheck
Building
# Build wheel package
just package
# Test the built package
just test-package
# Clean build artifacts
just clean
Available Just Commands
| Command | Description |
|---|---|
just setup |
Initialize development environment (Poetry deps + pre-commit hooks) |
just test |
Run unit tests with coverage report |
just typecheck |
Run static type checking with pyright |
just format |
Run formatting hooks (ruff, etc.) |
just validate |
Run all pre-commit hooks on all files |
just package |
Build wheel package into dist/ |
just test-package |
Build, install, and smoke-test the package |
just clean |
Clean build artifacts and temporary files |
just recreate-venv |
Recreate virtual environment with specific Python version |
just serve-http |
Run MCP server with HTTP transport (shared mode) |
just mcp-status |
Check if MCP HTTP server is running |
Project Structure
MCP-remove-background/
├── MCP_remove_background/
│ ├── __init__.py # Package exports
│ ├── cli.py # CLI entry point
│ ├── config.py # Configuration management
│ ├── constants.py # Constants and type definitions
│ ├── exceptions.py # Custom exceptions
│ ├── server.py # FastMCP server definition
│ ├── services/
│ │ └── background_remover.py # Core background removal logic
│ ├── tools/
│ │ └── remove_background.py # MCP tool definitions
│ └── utils/
│ └── file_utils.py # File handling utilities
├── tests/
│ ├── conftest.py # Pytest fixtures
│ ├── pytest.ini
│ ├── unit/
│ │ ├── test_constants.py
│ │ ├── test_exceptions.py
│ │ ├── test_background_remover.py
│ │ └── test_tools.py
│ ├── integration/
│ │ └── test_server.py
│ └── mocks/
│ └── rembg_mock.py
├── docs/
│ └── background-removal-mcp-plan.md
├── scripts/
│ ├── spack-ensure.sh
│ └── test-package.sh
├── pyproject.toml
├── justfile
├── README.md
└── spack.yaml
Spack Integration
This project uses Spack to manage system-level dependencies (like the Python interpreter). Spack is automatically installed to ~/.local/share/spack if not already available.
To manually activate the Spack environment:
source .spack-activate.sh
To update Spack packages:
spack -e . concretize --fresh-roots --force
spack -e . install
License
MIT License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。