img-mcp-server
Renders Apache ECharts option objects to image files server-side without a browser, with configurable dimensions, theme, background, scale, and output format.
Calls the OpenAI Images API to generate new images from prompts and edit local images, supporting model selection, size, quality, background, output format, and multi-image inputs.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@img-mcp-server Generate a 1024x1024 watercolor image of a cat astronaut."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
img-mcp-server
一站式 MCP 图片工具箱。把 AI 生成/修改 和常用的 本地图片处理 放进同一套工具里,方便 Agent 连续完成"生成 → 编辑 → 裁剪 → 压缩 → 转格式 → 提取色板"等工作流。
所有工具都把图片保存到本地,只返回绝对路径和元数据,不返回图片二进制。
当前版本 0.0.1。
发布包名为
img-mcp-server,安装后的命令行名称也是img-mcp-server。
工具总览
工具 | 能力 | 依赖 |
| 调用 OpenAI Images API 生成图片 |
|
| 调用 OpenAI Images API 修改本地图片(本地绝对路径) |
|
| 按像素区域裁剪 | sharp |
| 调整尺寸,支持 cover/contain/fill/inside/outside | sharp |
| 任意角度旋转、EXIF 自动校正 | sharp |
| PNG/JPEG/WebP/AVIF/TIFF/GIF 互转 | sharp |
| 按质量压缩,或压缩到指定文件大小 | sharp |
| 获取格式、尺寸、色彩空间、动画信息、主色/平均色等 | sharp |
| k-means 提取色板(hex/RGB/占比) | sharp |
| 纯色/近纯色背景去除,输出透明 PNG/WebP | sharp |
| 用无头 Chromium 渲染 HTML/URL 截图 | Chrome/Chromium |
| 服务端渲染 Apache ECharts(无需浏览器) | echarts + sharp |
Related MCP server: roundcut-mcp
要求
Node.js >= 22(OpenAI SDK 7.x 的要求)。
html_to_image需要本机有 Chrome/Chromium。Server 会自动查找:IMG_CHROME_PATHplaywright-core 已安装的浏览器缓存
系统常见路径中的 Google Chrome / Chromium / Edge
快速开始
MCP 客户端配置
Claude Desktop、Cursor 等使用 command / args / env 的客户端:
{
"mcpServers": {
"img": {
"command": "npx",
"args": ["-y", "img-mcp-server@0.0.1"],
"env": {
"OPENAI_API_KEY": "sk-...",
"OPENAI_BASE_URL": "https://api.openai.com/v1",
"IMG_MODEL": "gpt-image-2.6-sunburst",
"IMG_OUTPUT_DIR": "/absolute/path/to/img-output"
}
}
}
}只使用本地图片工具时可以完全省略 OPENAI_API_KEY,例如:
{
"mcpServers": {
"img": {
"command": "npx",
"args": ["-y", "img-mcp-server@0.0.1"],
"env": {
"IMG_OUTPUT_DIR": "/absolute/path/to/img-output"
}
}
}
}使用兼容网关(示例):
{
"mcpServers": {
"img": {
"command": "npx",
"args": ["-y", "img-mcp-server@0.0.1"],
"env": {
"OPENAI_API_KEY": "your-api-key",
"OPENAI_BASE_URL": "https://wukong.support/v1",
"IMG_MODEL": "gpt-image-2.6-sunburst",
"IMG_OUTPUT_DIR": "/absolute/path/to/img-output"
}
}
}
}OPENAI_BASE_URL 需要包含版本路径(通常是 /v1)。使用官方 OpenAI 时可以省略,默认 https://api.openai.com/v1。
环境变量
变量 | 必填 | 默认值 | 说明 |
| 仅生成/修改需要 | — | OpenAI 或兼容网关 API Key |
| 否 |
| API 基础地址 |
| 否 | — | OpenAI Organization ID |
| 否 | — | OpenAI Project ID |
| 否 |
| 生成/修改未指定 |
| 否 |
| 默认输出目录 |
| 否 |
| 生成/修改请求超时(毫秒) |
| 否 |
| OpenAI SDK 重试次数 |
| 否 |
| 下载 API 返回图片 URL 的超时(毫秒) |
| 否 | 自动检测 |
|
通用输入输出约定
所有本地图片输入都是运行 MCP Server 的机器上的绝对路径;相对路径直接报错。
所有生成/处理结果都写入本地文件,返回
path等元数据。同名文件自动追加
-1、-2,绝不覆盖已有文件。默认文件名格式:
img-<时间戳>-<随机串>.<扩展名>。扩展名以实际编码结果为准;例如请求 JPEG 但 API 返回 PNG 时,会保存为
.png并在format中如实标明。图片处理工具默认应用 EXIF 自动校正(
rotate_image可关闭)。动图(GIF/WebP)按首帧处理;
convert_image输出 GIF 时也是单帧。
生成与修改
generate_image
参数 | 类型 | 必填 | 说明 |
| string | 是 | 图片描述,最长 32000 字符 |
| string | 否 | 默认取 |
| integer (1–10) | 否 | 生成数量,默认 1 |
| string | 否 |
|
| string | 否 |
|
| string | 否 |
|
| string | 否 |
|
| integer (0–100) | 否 |
|
| string | 否 |
|
| string | 否 |
|
| integer (2–16) | 否 | GIF 帧数,仅 |
| integer | 否 | GIF 帧延迟(毫秒) |
| string | 否 | 终端用户稳定标识 |
| string | 否 | 已废弃,建议用 |
| object | 否 |
|
| string | 否 | 绝对输出目录 |
| string | 否 | 文件名(不含目录分隔符); |
edit_image
参数 | 类型 | 必填 | 说明 |
| string | string[] | 是 | 1–16 张图片的绝对路径;PNG/JPEG/WebP,每张 < 50 MB |
| string | 是 | 修改要求,最长 32000 字符 |
| string | 否 | PNG 遮罩绝对路径,< 4 MB;不能与 |
| string | 否 | 透明 PNG 叠加层绝对路径;不能与 |
| string | 否 | 默认取 |
| integer (1–10) | 否 | 生成数量 |
| string | 否 | 同 |
| string | 否 | 同 |
| string | 否 | 同 |
| string | 否 |
|
| string | 否 | 同 |
| integer (0–100) | 否 | 同 |
| string | 否 |
|
| integer (2–16) | 否 | 仅 GIF 输出 |
| integer | 否 | 仅 GIF 输出 |
| string | 否 | 终端用户稳定标识 |
| string | 否 | 已废弃,建议用 |
| object | 否 | 自定义 SVG 作者模型/推理强度 |
| string | 否 | 绝对输出目录 |
| string | 否 | 文件名 |
未暴露的 OpenAI 参数:stream、partial_images(工具只返回最终文件),以及 GPT Image 模型不支持的旧版 DALL·E 参数 response_format、style。
本地处理工具
除特别说明外,以下通用输出参数均可用于各处理工具:
参数 | 类型 | 说明 |
| string |
|
| integer (1–100) | JPEG/WebP/AVIF/TIFF 质量 |
| boolean | WebP/AVIF 无损编码 |
| integer (0–9) | PNG 压缩级别 |
| string | CSS 颜色;用于 letterbox、旋转留白或 JPEG 压平背景 |
| string | 绝对输出目录 |
| string | 输出文件名 |
crop_image
image, left, top, width, height(均必填,像素,零基坐标)。
resize_image
image 必填;width / height 至少一个。可选 fit(cover/contain/fill/inside/outside)、position、without_enlargement、kernel。
rotate_image
image 必填;angle(正数顺时针,可省略表示只做 EXIF 校正)、auto_orient(默认 true)。
convert_image
image + output_format(必填)。JPEG 输出会用 background(默认白色)压平透明通道。
compress_image
image;可选 output_format、quality、lossless、compression_level、target_size_bytes。
target_size_bytes仅支持 JPEG/WebP/AVIF,会二分搜索能塞进目标大小的最高质量。如果即使质量 1 也达不到目标,会输出最小结果,并在
details.target_reached=false中说明。返回
input_bytes、output_bytes、saved_bytes、ratio。
get_image_info
image;可选 include_stats(默认 true)。返回:
格式、宽高、色彩空间、通道数、位深、DPI、alpha、ICC profile 存在性、EXIF orientation
多帧信息(
pages、page_height、is_animated、loop、delay_ms)统计信息:
is_opaque、entropy、sharpness、dominant_color、average_color
不会返回原始 EXIF(避免泄露 GPS 等隐私)。
extract_palette
image;color_count(2–32,默认 8)。返回示例:
{
"operation": "extract_palette",
"source": { "path": "/abs/palette.png", "..." : "..." },
"colors": [
{ "hex": "#ff0000", "rgb": { "r": 255, "g": 0, "b": 0 }, "percentage": 25 },
{ "hex": "#00ff00", "rgb": { "r": 0, "g": 255, "b": 0 }, "percentage": 25 }
],
"details": { "method": "k-means", "sampled_pixels": 40000, "iterations": 3 }
}透明像素会被忽略;采样上限 256×256,保证大图也很快。
remove_background
参数 | 说明 |
| 必填,本地绝对路径 |
| 可选,十六进制背景色;省略时从图片边缘采样 |
| 0–100 颜色距离容差,默认 12 |
| 0–50 羽化范围,默认 1.5;0 为硬边 |
| 是否去除半透明边缘的背景色溢出,默认 |
|
|
| WebP 编码选项 |
这是颜色键控算法,适合纯色/近纯色背景的商品图、图标、截图;不是 AI 语义分割。复杂照片背景建议使用专门的抠图服务。
渲染工具
html_to_image
html 或 url 二选一;可选:
selector:只截取第一个匹配元素width(默认 1280)/height(默认 800)full_page(默认false)device_scale_factor(1–4)wait_until(load/domcontentloaded/networkidle)wait_ms、timeout_msbase_url:为 HTML 字符串中的相对资源提供 base URLbackground:页面背景色output_format/quality/lossless/compression_level
示例:
{
"name": "html_to_image",
"arguments": {
"html": "<div style=\"width:400px;padding:24px;background:#4f46e5;color:white\">Hello IMG</div>",
"width": 640,
"height": 360,
"device_scale_factor": 2,
"output_format": "png"
}
}没有浏览器时,Server 会返回明确错误。安装 Chrome/Chromium,或设置 IMG_CHROME_PATH。也可以安装与内置 playwright-core 匹配的 Chromium:
npx playwright@1.65.2 install chromiumecharts_to_image
option 必填,ECharts setOption 的配置对象(也接受 JSON 字符串)。服务端用 SVG renderer 渲染,无需浏览器。
其他参数:
参数 | 默认 | 说明 |
| 1000 | 图表宽度(CSS 像素) |
| 600 | 图表高度 |
| 默认主题 | 内置主题名(如 |
|
| 背景色,可传 |
| 1 | 光栅倍率;2 输出 2 倍分辨率(SVG 输出忽略此参数) |
|
|
|
示例:
{
"name": "echarts_to_image",
"arguments": {
"option": {
"xAxis": { "type": "category", "data": ["A", "B", "C"] },
"yAxis": { "type": "value" },
"series": [{ "type": "bar", "data": [3, 5, 2] }]
},
"width": 800,
"height": 500,
"scale": 2,
"output_format": "png"
}
}返回格式
生成/修改
{
"model": "gpt-image-2.6-sunburst",
"created": 1796364512,
"size": "1024x1024",
"quality": "low",
"output_format": "png",
"images": [
{
"path": "/home/user/img-output/generate-smoke.png",
"file_name": "generate-smoke.png",
"format": "png",
"mime_type": "image/png",
"width": 1024,
"height": 1024,
"bytes": 760034,
"revised_prompt": "A simple flat vector icon ...",
"source": "url",
"url": "https://example.com/generated.png"
}
],
"usage": { "input_tokens": 19, "output_tokens": 272, "total_tokens": 291 }
}本地处理
{
"operation": "crop_image",
"source": {
"path": "/abs/input.png",
"file_name": "input.png",
"format": "png",
"mime_type": "image/png",
"width": 200,
"height": 200,
"bytes": 1874
},
"image": {
"path": "/abs/img-output/crop-blue.png",
"file_name": "crop-blue.png",
"format": "png",
"mime_type": "image/png",
"width": 100,
"height": 100,
"bytes": 423
},
"details": {
"left": 0,
"top": 100,
"width": 100,
"height": 100,
"source_width": 200,
"source_height": 200
}
}渲染工具返回 { "operation", "image", "details" };get_image_info 返回 { "operation", "source", "metadata" };extract_palette 返回 { "operation", "source", "colors", "details" }。
本地开发
npm install
npm run build
# 单元测试(无需 API Key、无需浏览器)
npm test
# 本地工具全量测试(sharp + ECharts + Chromium)
npm run test:local
# 真实 API 测试(会消耗额度)
OPENAI_API_KEY=... OPENAI_BASE_URL=https://wukong.support/v1 npm run smoke
# 启动 server(stdio)
OPENAI_API_KEY=... node dist/index.js作为本地 MCP Server 调试时,把客户端配置中的 command 改为 node,args 改为 ["/绝对路径/dist/index.js"]。
License
MIT
Available Tools
12 toolscompress_imageCompress imageA
Re-encode a local image with a chosen quality/compression level, or binary-search the highest quality that fits target_size_bytes (JPEG, WebP, AVIF). Returns before/after sizes.
Inputs: image (required), quality, lossless, file_name, +5 more. Returns: image, source, details, operation
convert_imageConvert image formatA
Convert a local image to PNG, JPEG, WebP, AVIF, TIFF or GIF. JPEG output is flattened onto the given background color (white by default).
Inputs: image (required), output_format (required), quality, lossless, +4 more. Returns: image, source, details, operation
crop_imageCrop imageA
Crop a local image to a pixel region and save the result. Coordinates are zero-based and apply after EXIF auto-orientation. Returns the source and output paths plus metadata.
Inputs: top (required), left (required), image (required), width (required), +8 more. Returns: image, source, details, operation
echarts_to_imageRender ECharts to imageA
Render an Apache ECharts option object server-side (SVG renderer, no browser) and save it as PNG, JPEG, WebP, AVIF or SVG. Supports themes, background color and raster scale.
Inputs: option (required), scale, theme, width, +8 more. Returns: image, details, operation
edit_imageEdit imageA
Edit or extend one or more local images with the OpenAI Images API (POST /v1/images/edits), optionally using a mask or markup, then save the results to local disk and return absolute file paths plus metadata. Source images must be local absolute paths (PNG, JPEG or WebP, under 50 MB each, up to 16). Requires OPENAI_API_KEY. Image bytes are never returned.
Inputs: image (required), prompt (required), n, svg, +16 more. Returns: size, model, usage, images, +5 more
extract_paletteExtract color paletteARead-onlyIdempotent
Extract the dominant color palette from a local image using k-means clustering. Returns hex/RGB colors with coverage percentages; transparent pixels are ignored.
Inputs: image (required), color_count. Returns: colors, source, details, operation
generate_imageGenerate imageA
Generate one or more images with the OpenAI Images API (POST /v1/images/generations), save them to local disk, and return absolute file paths plus metadata. Image bytes are never returned. Requires OPENAI_API_KEY. The model defaults to IMG_MODEL (gpt-image-2.6-sunburst); set OPENAI_BASE_URL for OpenAI-compatible gateways.
Inputs: prompt (required), n, svg, size, +13 more. Returns: size, model, usage, images, +5 more
get_image_infoGet image infoARead-onlyIdempotent
Read local image metadata and optional pixel statistics: format, dimensions, color space, channels, alpha, density, animation info, dominant/average color, opacity, entropy and sharpness.
Inputs: image (required), include_stats. Returns: source, metadata, operation
html_to_imageRender HTML to imageA
Render an HTML string or HTTP(S) URL with headless Chromium and save a screenshot. Supports viewport size, full-page capture, element selectors, device scale factor and multiple output formats. Requires a local Chrome/Chromium (auto-detected or IMG_CHROME_PATH).
Inputs: url, html, width, height, +14 more. Returns: image, details, operation
remove_backgroundRemove backgroundA
Remove a solid or near-solid background from a local image using color-distance keying, with optional auto border sampling, tolerance, feathering and despill. Outputs a transparent PNG or WebP. This is not ML/AI segmentation.
Inputs: image (required), despill, feather, quality, +6 more. Returns: image, source, details, operation
resize_imageResize imageA
Resize a local image with sharp's cover/contain/fill/inside/outside fitting modes and save the result. At least one of width or height is required.
Inputs: image (required), fit, width, height, +10 more. Returns: image, source, details, operation
rotate_imageRotate imageB
Rotate a local image by an arbitrary angle (clockwise for positive values), optionally applying EXIF auto-orientation first, and save the result.
Inputs: image (required), angle, quality, lossless, +6 more. Returns: image, source, details, operation
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
Most tools have clearly distinct purposes: crop, resize, rotate, convert, and compress each target a specific operation, and generate vs edit are clearly separated. A few boundaries blur slightly: get_image_info already reports dominant/average color and opacity, which overlaps with extract_palette, and html_to_image vs echarts_to_image both render markup to an image though from different sources.
All twelve tools follow a consistent snake_case verb_noun pattern (crop_image, remove_background, generate_image, convert_image, get_image_info, extract_palette, etc.). The two rendering tools (html_to_image, echarts_to_image) consistently share the same noun_to_image form.
Twelve tools sits comfortably in the well-scoped 3-15 range for an image processing server. Each tool covers a distinct capability (geometry ops, format/quality, AI generation, metadata, rendering) with no redundant entries.
Coverage is strong for a local image pipeline: geometric transforms, format/quality conversion, background removal, AI generate/edit, metadata, palette extraction, and two rendering paths. Minor gaps remain—no flip/mirror, no overlay/watermark/text compositing, and no batch operation across multiple files—but agents can work around these with existing tools.
Related MCP Connectors
Image & PDF tools for AI agents: compress, convert, resize, PDF, AI vision, pipeline.
Generate images, GIFs, videos, and PDFs from HTML, URLs, or templates — from your AI agent.
Image processing for AI agents: resize, convert, compress, crop, and web-ready AI-generated images.
PDF, image, video, OCR, screenshot, SQL, QR and text tools for agents. No API key, no signup.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI agents to perform image processing tasks such as sprite sheet splitting, resizing, cropping, and batch operations on local images.MIT
- AlicenseAqualityCmaintenanceEnables AI agents to perform local image operations such as circle cropping, cropping, resizing, compressing, converting, and inspecting images without uploading files or making network calls.789 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to generate and edit local PNG images from text prompts or reference images through an OpenAI-compatible Images API, with selectable style templates and offline reference examples.MIT
- AlicenseNot gradedqualityCmaintenanceEnables coding agents to generate and edit images from text prompts, reference images, or saved files through any OpenAI-images-compatible backend, returning each result inline as a downscaled preview (full-res on disk) so the agent can inspect and iterate. Also supports prompt expansion, exact-pixel resizing/recompression, and listing or re-serving saved images.AGPL 3.0