图像处理服务器

提供图像优化、格式转换及上传至Vercel Blob存储的一站式处理服务。

  • by jbergant
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 jbergant/mcp_image_processor_to_vercel_blob

使用说明

图像处理器MCP服务器

此MCP服务器提供用于图像处理和上传到Vercel Blob存储的工具。它允许您:

  1. 优化和调整图像大小(来自本地文件或URL)
  2. 将图像转换为WebP格式
  3. 将两个版本上传到Vercel Blob存储

特性

  • 图像优化:调整和优化图像以获得更好的性能
  • WebP转换:将图像转换为WebP格式以减小文件大小
  • Vercel Blob集成:自动将处理后的图像上传到Vercel Blob存储
  • 可定制尺寸:指定图像大小调整的自定义尺寸
  • URL支持:处理来自外部URL的图像

安装

服务器已在MCP设置文件中安装和配置。它使用环境变量中的Vercel Blob令牌。

用法

您可以使用Claude中的MCP服务器 use_mcp_tool 功能:

对于本地图像

<use_mcp_tool>
<server_name>image-processor</server_name>
<tool_name>process_and_upload_image</tool_name>
<arguments>
{
  "imagePath": "/path/to/image.png",
  "newName": "new-image-name",
  "width": 550,
  "height": 300
}
</arguments>
</use_mcp_tool>

对于来自URL的图像

<use_mcp_tool>
<server_name>image-processor</server_name>
<tool_name>process_and_upload_image_from_url</tool_name>
<arguments>
{
  "imageUrl": "https://example.com/image.jpg",
  "newName": "new-image-name",
  "width": 550,
  "height": 300
}
</arguments>
</use_mcp_tool>

本地图像参数

  • imagePath (必填):要处理的图像文件的路径
  • newName (必填):已处理图像的新名称(不带扩展名)
  • width (可选):调整图像大小的宽度(默认值:550)
  • height (可选):调整图像大小的高度(默认值:300)

URL图像的参数

  • imageUrl (必填):要处理的图像的URL
  • newName (必填):已处理图像的新名称(不带扩展名)
  • width (可选):调整图像大小的宽度(默认值:550)
  • height (可选):调整图像大小的高度(默认值:300)

响应

服务器将返回具有以下结构的JSON响应:

{
  "success": true,
  "message": "Successfully processed and uploaded image: new-image-name",
  "results": {
    "png": {
      "fileName": "new-image-name_small.png",
      "localPath": "/path/to/temp/new-image-name_small.png",
      "blobUrl": "https://vercel-blob-url/new-image-name_small.png"
    },
    "webp": {
      "fileName": "new-image-name.webp",
      "localPath": "/path/to/temp/new-image-name.webp",
      "blobUrl": "https://vercel-blob-url/new-image-name.webp"
    }
  }
}

实现细节

服务器使用:

  • 夏普:用于图像处理和优化
  • @vercel/blob:用于上传到Vercel Blob存储
  • fs额外:用于文件系统操作

例子

示例1:处理本地图像

<use_mcp_tool>
<server_name>image-processor</server_name>
<tool_name>process_and_upload_image</tool_name>
<arguments>
{
  "imagePath": "/pathto_file/image_name.png",
  "newName": "test-processed-image",
  "width": 550,
  "height": 300
}
</arguments>
</use_mcp_tool>

示例2:处理来自URL的图像

<use_mcp_tool>
<server_name>image-processor</server_name>
<tool_name>process_and_upload_image_from_url</tool_name>
<arguments>
{
  "imageUrl": "https://pplx-res.cloudinary.com/image/upload/v1749567759/pplx_project_search_images/6dff647e4fb1083aecf9ea6b1d49ea19386be588.jpg",
  "newName": "cloud-image",
  "width": 550,
  "height": 300
}
</arguments>
</use_mcp_tool>

这两个例子将:

  1. 拍摄图像(来自本地路径或URL)
  2. 将其优化并调整为550x300像素
  3. 创建后缀为“_small”的PNG版本
  4. 创建WebP版本
  5. 将两者都上传到Vercel Blob
  6. 返回上传图像的URL