Requires Node.js runtime environment (version 20 or higher recommended) to execute the MCP server for image compression functionality
TinyPNG MCP Server 使用指南
本项目是一个基于 Model Context Protocol (MCP) 的图片压缩服务器,使用 TinyPNG API 来优化图片。
功能特性
✅ 支持批量压缩目录中的所有图片
✅ 支持图片格式转换(PNG、JPEG、WebP、AVIF 互转)
✅ 支持图片尺寸调整和智能裁剪
✅ 支持多种图片格式:
.png
,.jpg
,.jpeg
,.webp
,.avif
✅ 自动覆盖原始文件(节省存储空间)
✅ 详细的压缩报告(文件大小变化、压缩比例)
✅ 安全的 API 密钥管理(通过环境变量)
✅ 完整的错误处理和日志记录
前置环境
需要安装Node.js环境
Recommend Node.js version >= 20
安装配置
1. 获取 TinyPNG API 密钥
使用邮箱注册账号
获取免费的 API 密钥(每月 500 次免费压缩)
2. 配置 MCP 客户端
创建或修改你的 MCP 配置文件,目前支持的客户端(或命令行工具)有Cursor,gemini-cli,Claude Code,Claude Desktop,Trae...
使用方法
可用工具
本 MCP 服务器提供三个核心工具,满足不同的图片处理需求:
工具名称 | 主要功能 | 适用场景 |
| 批量压缩图片 | 减少文件大小,优化存储 |
| 调整图片尺寸 | 生成缩略图,适配不同设备 |
| 转换图片格式 | Web 优化,兼容性处理 |
minify_image
压缩指定目录中的所有支持的图片文件。支持嵌套结构。
参数:
directoryPath
(string): 包含要压缩图片的目录路径
示例:
输出示例:
resize_image
调整指定图片尺寸。
参数:
method参数模式说明
模式 | 说明 | 适用场景 |
| 保持宽高比,适配指定尺寸 | 缩略图生成 |
| 按比例缩放 | 等比缩放 |
| 裁剪填充指定尺寸 | 封面图制作 |
| 智能缩略图模式 | 头像处理 |
示例:
测试结果:
convert_image
转换图片格式,支持 PNG、JPEG、WebP、AVIF 格式之间的相互转换。
参数:
支持的格式:
image/png
- PNG 格式image/jpeg
- JPEG 格式image/webp
- WebP 格式image/avif
- AVIF 格式
示例:
输出示例:
应用场景:
Web 优化: 将 PNG 转换为体积更小的 WebP/AVIF 格式
兼容性处理: 为旧浏览器提供 JPEG/PNG 备选格式
透明处理: 将透明 PNG 转换为 JPEG 并添加背景色
现代格式支持: 利用 AVIF/WebP 的高压缩比优势
支持的图片格式
根据 TinyPNG 官方文档,支持以下格式:
PNG - 便携式网络图形
JPEG/JPG - 联合图像专家组格式
WebP - 现代网络图片格式
AVIF - AV1 图像文件格式
限制说明
免费账户: 每月 500 次 API 调用(包括压缩、调整尺寸、格式转换)
付费账户: 根据订阅计划不同
文件大小: 单个文件最大 5MB
并发请求: TinyPNG 有合理的速率限制
API 计费规则:
图片压缩(
minify_image
): 每张图片 1 次调用尺寸调整(
resize_image
): 每张图片 1 次调用格式转换(
convert_image
): 每张图片 1 次调用组合操作会累计调用次数
相关链接
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables batch image compression and resizing using the TinyPNG API. Supports PNG, JPEG, WebP, and AVIF formats with detailed compression reports and multiple resize modes.
Related MCP Servers
- AsecurityAlicenseAqualityEnables AI assistants to download images from URLs and perform basic image optimization tasks.Last updated -2811Apache 2.0
- AsecurityAlicenseAqualityImage Tools MCP is a Model Context Protocol (MCP) service that retrieves image dimensions and compresses images from URLs and local files using the TinyPNG API. It supports converting images to formats like webp, jpeg/jpg, and png, providing detailed information on width, height, type, and compressiLast updated -2147MIT License
- Apache 2.0
- AsecurityFlicenseAqualityEnables optimization, conversion to WebP, and uploading of images to Vercel Blob storage, supporting both local files and external URLs.Last updated -21