@bangdao-ai/mcp-image-compressor
v1.0.1
Published
MCP Server for image compression
Readme
MCP Image Compressor
基于 @modelcontextprotocol/sdk 实现的图片压缩 MCP Server。
功能特性
- 压缩图片文件(JPEG、PNG、WebP 格式)
- 可调节输出质量(1-100)
- 支持按最大宽度/高度等比缩放
- 支持限制最大文件大小
- 支持格式转换
环境要求
- Node.js >= 18.0.0
- npm >= 9.0.0
安装
npm install构建
npm run build使用方式
作为 MCP Server 运行
npm start在 Cursor 中使用(npx 方式)
在 Cursor 设置中添加 MCP Server:
- 打开 Cursor 设置 → Features → MCP
- 点击 "Add New MCP Server"
配置 server:
{ "mcpServers": { "image-compressor": { "command": "npx", "args": ["-y", "@bangdao-ai/mcp-image-compressor"] } } }重启 Cursor 后,在 AI 对话框中即可使用图片压缩功能
在 Cursor 中使用(本地开发方式)
{
"mcpServers": {
"image-compressor": {
"command": "node",
"args": ["/path/to/mcp/dist/index.js"]
}
}
}工具参数
| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | inputPath | string | 是 | - | 输入图片的绝对路径 | | outputPath | string | 是 | - | 输出图片的绝对路径 | | quality | number | 否 | 80 | 输出质量 (1-100) | | maxWidth | number | 否 | - | 最大宽度(保持宽高比) | | maxHeight | number | 否 | - | 最大高度(保持宽高比) | | maxSize | number | 否 | - | 最大文件大小(MB),如 0.5 表示 500KB | | format | string | 否 | jpeg | 输出格式:jpeg, png, webp |
返回结果示例
{
"success": true,
"message": "图片压缩成功",
"input": {
"path": "/path/to/input.jpg",
"format": "jpeg",
"size": 2846064,
"width": 4214,
"height": 2846
},
"output": {
"path": "/path/to/output.jpg",
"format": "jpeg",
"size": 407707,
"width": 4214,
"height": 2846,
"quality": 12
},
"compressionRatio": "85.67%"
}发布到 npm
# 修改 package.json 中的版本号
npm publish依赖
@modelcontextprotocol/sdk- MCP 协议 SDKsharp- 高性能图片处理库zod- TypeScript 模式验证
