Rembg MCP Server

Rembg MCP Server

Enables AI-powered background removal from images using multiple specialized models including u2net, birefnet, and isnet. Supports both single image processing and batch folder operations with advanced options like alpha matting and mask-only output.

Category
访问服务器

README

Rembg MCP Server

An MCP (Model Context Protocol) server for the rembg background removal library. Remove image backgrounds using AI models through Claude Code, Claude Desktop, Cursor, and other MCP-compatible tools.

🎯 Features

  • 🖼️ Image Processing: Remove backgrounds from single images or batch process folders
  • 🤖 Multiple AI Models: u2net, birefnet, isnet, sam, and more specialized models
  • ⚡ Performance Optimized: Model session reuse for efficient batch processing
  • 🎨 Advanced Options: Alpha matting, mask-only output, custom backgrounds
  • 🌍 Cross-Platform: Support for Windows, macOS, and Linux
  • 🔧 Easy Integration: Works with Claude Desktop, Claude Code CLI, Cursor IDE

📦 Quick Start

🚀 One-Click Installation

Linux/macOS

git clone <repository-url>
cd rembg-mcp
./setup.sh

Windows

git clone <repository-url>
cd rembg-mcp
setup.bat

The setup scripts will automatically:

  • Check Python 3.10+ requirement
  • Create virtual environment
  • Install all dependencies
  • Configure MCP server
  • Test the installation
  • Guide you through AI model downloads

🔧 Manual Installation

If you prefer manual installation or need custom configuration:

  1. Create virtual environment:
python3 -m venv rembg
source rembg/bin/activate  # Linux/macOS
# or
rembg\Scripts\activate.bat  # Windows
  1. Install dependencies:
pip install --upgrade pip
pip install mcp "rembg[cpu,cli]" pillow
pip install -e .
  1. Test installation:
python test_server.py
python validate_setup.py
  1. Download AI models:
./download_models.sh     # Linux/macOS
# or
python download_models.py  # Windows (from activated venv)
  1. For GPU support:
pip install -e ".[gpu]"

🔧 MCP Configuration

Claude Desktop Setup

  1. Find your Claude Desktop config file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
  2. Add the rembg server configuration:

{
  "mcpServers": {
    "rembg": {
      "command": "/path/to/rembg-mcp/start_server.sh",
      "cwd": "/path/to/rembg-mcp",
      "env": {
        "REMBG_HOME": "~/.u2net",
        "OMP_NUM_THREADS": "4"
      }
    }
  }
}
  1. Replace /path/to/rembg-mcp with your actual project path

  2. Restart Claude Desktop

Testing Your Setup

After configuration, test your MCP server:

  1. Start the server manually:
./start_server.sh  # Linux/macOS
# or
start_server.bat   # Windows
  1. Verify MCP connection in Claude Desktop:

    • Look for the rembg tools in your Claude conversation
    • Try a simple command: "List available MCP tools"
  2. Test with a sample image:

    • Ask Claude: "Use rembg-i to remove the background from test.jpg"
    • The server will process your request and return results

Claude Code CLI Setup

Add to your Claude Code settings:

{
  "mcpServers": {
    "rembg": {
      "command": "/path/to/rembg-mcp/start_server.sh",
      "cwd": "/path/to/rembg-mcp",
      "env": {
        "REMBG_HOME": "~/.u2net",
        "OMP_NUM_THREADS": "4"
      }
    }
  }
}

Cursor IDE Setup

Add to your Cursor settings or workspace .cursor/settings.json:

{
  "mcp.servers": {
    "rembg": {
      "command": "/path/to/rembg-mcp/start_server.sh",
      "args": [],
      "cwd": "/path/to/rembg-mcp"
    }
  }
}

Windows Configuration

For Windows users, use start_server.bat instead:

{
  "mcpServers": {
    "rembg": {
      "command": "C:\\path\\to\\rembg-mcp\\start_server.bat",
      "cwd": "C:\\path\\to\\rembg-mcp"
    }
  }
}

🚀 How to Use

Once configured, you can use the rembg tools directly in your MCP-compatible application:

Basic Usage Examples

Single Image Processing:

Remove the background from my photo.jpg and save it as photo_nobg.png

Batch Processing:

Process all images in my Photos folder and remove their backgrounds

Advanced Processing:

Use the birefnet-portrait model to remove backgrounds from all portrait photos in my folder, apply alpha matting for better edges, and save them to a new folder

🛠️ Available MCP Tools

rembg-i - Single Image Background Removal

Removes background from a single image file with high precision.

Required Parameters:

  • input_path: Path to the source image file
  • output_path: Where to save the processed image

Optional Parameters:

  • model: AI model to use (default: "u2net")
  • alpha_matting: Improve edge quality (default: false)
  • only_mask: Output black/white mask only (default: false)

Supported formats: JPG, PNG, BMP, TIFF, WebP

rembg-p - Batch Folder Processing

Processes all images in a folder automatically.

Required Parameters:

  • input_folder: Source folder containing images
  • output_folder: Destination folder for processed images

Optional Parameters:

  • model: AI model to use (default: "u2net")
  • alpha_matting: Improve edge quality (default: false)
  • only_mask: Output masks only (default: false)
  • file_extensions: File types to process (default: common image formats)

Features:

  • Automatically finds all supported images
  • Preserves original filenames with .out.png suffix
  • Detailed progress reporting
  • Error handling for individual files

🤖 Supported AI Models

Model Use Case Size Quality
u2net General purpose (default) Medium Good
u2netp Lightweight version Small Good
u2net_human_seg Human subjects Medium Good
u2net_cloth_seg Clothing segmentation Medium Good
silueta Lightweight general Small Good
isnet-general-use High quality general Large Excellent
isnet-anime Anime characters Large Excellent
birefnet-general High accuracy general Large Excellent
birefnet-portrait Portrait photos Large Excellent
birefnet-massive Massive dataset trained X-Large Best
sam Segment Anything (prompt-based) Large Variable

🎯 Model Recommendations

For beginners: Start with u2net (default) - good balance of speed and quality

For best quality: Use birefnet-general or birefnet-massive

For portraits: Use birefnet-portrait - specialized for human subjects

For anime/cartoons: Use isnet-anime - optimized for animated content

For speed: Use u2netp or silueta - faster processing for batch jobs

📥 Downloading Models

Models are downloaded automatically when first used, but you can pre-download them:

# Interactive selection (recommended)
./download_models.sh              # Linux/macOS

# Download specific models
./download_models.sh u2net birefnet-portrait

# Download all models
./download_models.sh all

# Windows (from activated virtual environment)
python download_models.py         # Interactive
python download_models.py u2net birefnet-portrait

Models are cached in ~/.u2net/ and only need to be downloaded once.

🔧 Configuration

Environment Variables

  • REMBG_HOME: Model storage directory (default: ~/.u2net)
  • OMP_NUM_THREADS: Number of CPU threads for processing (default: 4)
  • MODEL_CHECKSUM_DISABLED: Skip model checksum verification

Advanced Options

  • Alpha Matting: Improves edge quality but increases processing time
  • Mask Only: Returns black/white mask instead of transparent cutout
  • Custom Background Colors: Replace transparent areas with solid colors
  • Batch Processing: Automatically reuses model sessions for efficiency

📁 Project Structure

rembg-mcp/
├── rembg_mcp/
│   ├── __init__.py
│   └── server.py                      # Main MCP server implementation
├── rembg/                             # Virtual environment (git-ignored)
├── setup.sh                           # Linux/macOS setup script
├── setup.bat                          # Windows setup script
├── start_server.sh                    # Linux/macOS server startup
├── start_server.bat                   # Windows server startup (generated)
├── pyproject.toml                     # Python package configuration
├── claude_desktop_config.json         # Claude Desktop config (Linux/macOS)
├── claude_desktop_config_windows.json # Claude Desktop config (Windows)
├── test_server.py                     # Installation test
├── validate_setup.py                  # Comprehensive setup validation
├── download_models.py                 # AI model download utility (Python)
├── download_models.sh                 # AI model download script (Linux/macOS)
├── example_usage.py                   # Usage examples
├── README.md                          # This file
├── USAGE_CN.md                       # Chinese documentation
└── CLAUDE.md                         # Claude Code context file

🚨 Troubleshooting

Common Issues

MCP Server Not Found

  • Verify the command path in your MCP configuration
  • Ensure the script is executable: chmod +x start_server.sh
  • Check that the virtual environment exists: ls rembg/

Python Version Issues

python --version  # Must be 3.10+
# If wrong version, install Python 3.10+ and recreate venv

Model Download Problems

# Clear model cache and re-download
rm -rf ~/.u2net

# Re-download models manually
./download_models.sh              # Linux/macOS
python download_models.py         # Windows

# Download a specific model
./download_models.sh u2net        # Linux/macOS
python download_models.py u2net   # Windows

Memory or Performance Issues

# Reduce CPU threads
export OMP_NUM_THREADS=2

# Use lighter models (u2netp, silueta) instead of large ones

Installation Problems

# Clean reinstall
rm -rf rembg/
./setup.sh  # Or setup.bat on Windows

Getting Help

  • Run python validate_setup.py for detailed diagnostics
  • Check server logs when starting manually
  • Ensure your MCP client supports the latest protocol version

📚 Additional Resources

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • danielgatis/rembg - The excellent background removal library
  • Anthropic - For the MCP protocol and Claude
  • The open source community for the various AI models

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选