Skip to main content

MCP服务器:图像编辑工具,提供显著性分割、背景移除等图像处理功能

Project description

MCP 图像抠图服务器

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

功能特性

  • 智能抠图: 使用火山引擎的显著性分割技术,自动识别并抠出图像中的主要对象
  • 批量处理: 支持同时处理多张图像
  • 自动上传: 本地图片会先自动上传到服务器获取可访问链接,抠图结果也会自动上传并返回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"

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

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"
      }
    }
  }
}

可用工具

image_cutout

智能图像抠图,使用显著性分割自动识别并抠出图像中的主要对象。支持直接提供本地图片路径,工具会先上传到服务器(https://www.mcpcn.cc)生成可访问URL,然后进行抠图,最终结果同样自动上传并返回图片URL。

参数:

  • image_paths: 本地图片文件路径列表,会自动上传到服务器后再进行抠图
  • image_urls: (可选) 已经可访问的图像URL列表,保留向后兼容

返回:

  • 单张图片:直接返回图片URL
  • 多张图片:返回所有图片URL的列表

示例:

请帮我抠出这张图片中的主要对象:/Users/me/Pictures/product.png
批量抠图这些图片:
- /Users/me/Pictures/product1.png
- /Users/me/Pictures/product2.jpg
- https://example.com/image1.jpg
- https://example.com/image2.jpg

抠图原理

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

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

上传功能

输入输出都会通过同一上传服务处理:

  1. 当提供本地图片路径时,工具会先验证图片并上传到 https://www.mcpcn.cc/api/fileUploadAndDownload/uploadMcpFile,获取可公开访问的URL;
  2. 使用这些URL调用火山引擎显著性分割接口完成抠图;
  3. 将抠图结果保存为PNG后重新上传至同一服务器并返回最终URL;
  4. 支持批量处理,多张图片会依次上传和处理。

上传接口返回格式

{
    "code": 0,
    "data": {
        "url": "https://juezhi.oss-cn-shanghai.aliyuncs.com/file/uploads/mcp/xxx.webp"
    },
    "msg": "成功"
}

注意事项

  1. 确保图像URL可以公开访问
  2. 处理结果会以base64格式返回,大图像可能需要较长处理时间
  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

开发

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_image_cutout-0.2.5.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_image_cutout-0.2.5-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_image_cutout-0.2.5.tar.gz.

File metadata

  • Download URL: mcp_image_cutout-0.2.5.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mcp_image_cutout-0.2.5.tar.gz
Algorithm Hash digest
SHA256 94f3f4d18dcb45a61ae12ad51caec1de49ce61bf2bbbaf316d4e2f7e95079cbf
MD5 a29b6ded4ddc68c890ecc4541238446a
BLAKE2b-256 611c97c3234d49ae45250a4e9a36aabbde4f04ecfe9036cd1382221ef73ca98d

See more details on using hashes here.

File details

Details for the file mcp_image_cutout-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_image_cutout-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c0b16812c2a9b84504f392adcc26f13835180df4c4d87b8375509a999e9e5d2b
MD5 6d27151cd6e868e299b5119a75fbb8a4
BLAKE2b-256 78f142c4d2832bc12454c78a8e234b80dd512d5191f7300fde9e18c40ccff4f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page