Skip to main content

MCP 图像抠图服务器

这是一个基于Model Context Protocol (MCP)的服务器,专门提供火山引擎图像抠图功能。

功能特性

  • 智能抠图: 使用火山引擎的显著性分割技术,自动识别并抠出图像中的主要对象
  • 单图处理: 每次处理一张图像
  • 结果上传: 原图通过 image_url 传给火山引擎,抠图结果上传到 UPLOAD_URL 配置的文件服务并返回URL
  • 高精度: 基于显著性检测的精确分割算法

安装

从 PyPI 安装

pip install mcp-image-cutout

从源码安装

git clone https://github.com/fengjinchao/mcp-image-cutout.git
cd mcp-image-cutout
pip install -e .

2. 配置API密钥

推荐使用环境变量设置API密钥:

export VOLC_ACCESS_KEY="your_access_key"
export VOLC_SECRET_KEY="your_secret_key"
export UPLOAD_URL="https://example.com/api/upload"

或者在代码中直接设置(不推荐用于生产环境)。

3. 运行服务器

# 使用命令行工具
mcp-image-cutout

# 或直接运行模块
python -m mcp_image_cutout.server

在Claude Desktop中使用

在Claude Desktop的配置文件中添加以下配置:

macOS/Linux: ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "抠图工具": {
      "command": "mcp-image-cutout",
      "env": {
        "VOLC_ACCESS_KEY": "your_access_key",
        "VOLC_SECRET_KEY": "your_secret_key",
        "UPLOAD_URL": "https://example.com/api/upload"
      }
    }
  }
}

可用工具

image_cutout

智能图像抠图,使用显著性分割自动识别并抠出图像中的主要对象,上传处理后的PNG图片并返回URL。

参数:

  • image_url: 图像URL

返回:

  • data 为上传后的图片URL
  • url 为上传后的图片URL

示例:

请帮我抠出这张图片中的主要对象:https://example.com/image.jpg
请帮我抠出这张图片中的主要对象:https://example.com/image.jpg

抠图原理

使用的 saliency_seg 显著性分割算法:

  • 基于视觉显著性检测图像中最重要的区域
  • 精确分割显著对象的轮廓
  • 生成高质量的抠图结果
  • 适用于各种复杂背景的图像处理

返回格式

抠图完成后,系统会把处理后的PNG图片上传到 UPLOAD_URL 指向的文件服务,并返回上传后的图片URL。待处理原图不会在MCP内部上传,只会把原始 image_url 提交给火山引擎接口。

返回格式示例:

{
    "success": true,
    "data": "https://example.com/files/cutout.png",
    "url": "https://example.com/files/cutout.png",
    "message": "处理成功,已上传 1 张抠图结果",
    "processed_count": 1,
    "total_count": 1
}

注意事项

  1. 确保图像URL可以公开访问
  2. 处理结果会上传到 UPLOAD_URL,请确保上传服务可访问并返回 data.url
  3. API调用有频率限制,请合理使用
  4. 生产环境中请使用环境变量设置API密钥

故障排除

常见问题

  1. 服务器无法启动

    • 检查Python版本(需要3.10+)
    • 确认所有依赖已正确安装
  2. API调用失败

    • 验证API密钥是否正确
    • 检查网络连接
    • 确认图像URL可访问
  3. Claude Desktop中看不到工具

    • 检查配置文件语法
    • 确认路径是绝对路径
    • 重启Claude Desktop

日志查看

服务器日志会输出到stderr,可以通过以下方式查看:

# 查看Claude Desktop的MCP日志
tail -f ~/Library/Logs/Claude/mcp-server-图像编辑.log

开发

如需修改或扩展功能,请参考:

Metadata

Release files for mcpcn-image-cutout 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcpcn-image-cutout 0.1.3
File Size Uploaded
mcpcn_image_cutout-0.1.3.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcpcn-image-cutout 0.1.3
File Interpreter ABI Platform
mcpcn_image_cutout-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.7 kB

Release files / mcpcn_image_cutout-0.1.3.tar.gz

Download URL mcpcn_image_cutout-0.1.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a650aee5f3855ad7806b7f9884c53647e62dde87ab43ba5e334101e3d182726c
BLAKE2b-256 checksum
How to use checksums
fe13a91acfeccd4a4e69aa64ddf52bc652cb7729b155182f4da4e825e8562495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.16

Release files / mcpcn_image_cutout-0.1.3-py3-none-any.whl

Download URL mcpcn_image_cutout-0.1.3-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ce1495776aa9bfebe45d3901ee9d6b3df14b9aab0b62a63eeb086f2c08fcb2c
BLAKE2b-256 checksum
How to use checksums
0c8b21fdd8850517c98850d241ed1106d69117c7718f1554fe1752d66cfa632c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.16

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page