图像压缩工具 MCP
图像工具MCP是一种模型上下文协议(MCP)服务,它通过TinyPNG API从URL和本地文件中检索图像尺寸并压缩图像。它支持将图像转换为webp、jpeg/jpg和png等格式,并提供关于宽度、高度、类型和压缩的详细信息。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"image-tools": {
"args": [
"image-tools-mcp"
],
"command": "npx",
"env": {
"FIGMA_API_TOKEN": "\u003cYOUR_FIGMA_API_TOKEN\u003e",
"TINIFY_API_KEY": "\u003cYOUR_TINIFY_API_KEY\u003e"
}
}
}
}
该服务需要配置环境变量:TINIFY_API_KEY
可用工具 (4 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
get_image_size 1 个参数 需填 1 项
Get the size of an image from URL
必填参数:options
get_local_image_size 1 个参数 需填 1 项
Get the size of a local image
必填参数:options
compress_image_from_url 1 个参数 需填 1 项
Compress a single image from URL using TinyPNG API (only supports image files, not folders)
必填参数:options
compress_local_image 1 个参数 需填 1 项
Compress a single local image file using TinyPNG API (only supports image files, not folders)
必填参数:options
服务介绍
图像工具 MCP
一个用于获取图像尺寸和压缩图像的模型上下文协议(MCP)服务,支持从 URL 和本地文件来源进行操作。
功能
- 从 URL 获取图像尺寸
- 从本地文件获取图像尺寸
- 使用 TinyPNG API 压缩来自 URL 的图像
- 使用 TinyPNG API 压缩本地图像
- 转换图像格式(webp, jpeg/jpg, png)
- 返回宽度、高度、类型、MIME 类型以及压缩信息
示例结果


从 Figma URL 下载并压缩

使用方法
作为 MCP 服务使用
本服务提供了五个工具功能:
get_image_size- 获取远程图像的尺寸get_local_image_size- 获取本地图像的尺寸compress_image_from_url- 使用 TinyPNG API 压缩远程图像compress_local_image- 使用 TinyPNG API 压缩本地图像figma- 通过 Figma API 获取图像链接并使用 TinyPNG API 压缩它们
客户端集成
要使用此 MCP 服务,您需要从 MCP 客户端连接到它。以下是如何与不同客户端集成的示例:
与 Claude Desktop 配合使用
- 从 claude.ai/download 安装 Claude Desktop
- 获取 TinyPNG API 密钥:访问 TinyPNG 并获取您的 API 密钥
- 通过编辑配置文件来配置 Claude Desktop 以使用此 MCP 服务器:
{
"mcpServers": {
"image-tools": {
"command": "npx",
"args": ["image-tools-mcp"],
"env": {
"TINIFY_API_KEY": "<YOUR_TINIFY_API_KEY>",
"FIGMA_API_TOKEN": "<YOUR_FIGMA_API_TOKEN>"
}
}
}
}
- 重启 Claude Desktop
- 请求 Claude 获取图像尺寸:“你能告诉我这个图像的尺寸吗:https://example.com/image.jpg”
- 请求 Claude 压缩图像:“你能压缩这个图像吗:https://example.com/image.jpg”
- 请求 Claude 压缩本地图像:“你能压缩这个图像吗:D:/path/to/image.png”
- 请求 Claude 压缩本地图像文件夹:“你能压缩这个文件夹吗:D:/imageFolder”
- 请求 Claude 从 Figma API 获取图像链接:“你能从 Figma API 获取图像链接吗:https://www.figma.com/file/XXXXXXX”
与 MCP 客户端库配合使用
import { McpClient } from "@modelcontextprotocol/client";
// Initialize the client
const client = new McpClient({
transport: "stdio" // or other transport options
});
// Connect to the server
await client.connect();
// Get image dimensions from URL
const urlResult = await client.callTool("get_image_size", {
options: {
imageUrl: "https://example.com/image.jpg"
}
});
console.log(JSON.parse(urlResult.content[0].text));
// Output: { width: 800, height: 600, type: "jpg", mime: "image/jpeg" }
// Get image dimensions from local file
const localResult = await client.callTool("get_local_image_size", {
options: {
imagePath: "D:/path/to/image.png"
}
});
console.log(JSON.parse(localResult.content[0].text));
// Output: { width: 1024, height: 768, type: "png", mime: "image/png", path: "D:/path/to/image.png" }
// Compress image from URL
const compressUrlResult = await client.callTool("compress_image_from_url", {
options: {
imageUrl: "https://example.com/image.jpg",
outputFormat: "webp" // Optional: convert to webp, jpeg/jpg, or png
}
});
console.log(JSON.parse(compressUrlResult.content[0].text));
// Output: { originalSize: 102400, compressedSize: 51200, compressionRatio: "50.00%", tempFilePath: "/tmp/compressed_1615456789.webp", format: "webp" }
// Compress local image
const compressLocalResult = await client.callTool("compress_local_image", {
options: {
imagePath: "D:/path/to/image.png",
outputPath: "D:/path/to/compressed.webp", // Optional
outputFormat: "image/webp" // Optional: convert to image/webp, image/jpeg, or image/png
}
});
console.log(JSON.parse(compressLocalResult.content[0].text));
// Output: { originalSize: 102400, compressedSize: 51200, compressionRatio: "50.00%", outputPath: "D:/path/to/compressed.webp", format: "webp" }
// Fetch image links from Figma API
const figmaResult = await client.callTool("figma", {
options: {
figmaUrl: "https://www.figma.com/file/XXXXXXX"
}
});
console.log(JSON.parse(figmaResult.content[0].text));
// Output: { imageLinks: ["https://example.com/image1.jpg", "https://example.com/image2.jpg"] }
### Tool Schemas
#### get_image_size
```typescript
{
options: {
imageUrl: string // URL of the image to retrieve dimensions for
}
}
get_local_image_size
{
options: {
imagePath: string // Absolute path to the local image file
}
}
compress_image_from_url
{
options: {
imageUrl: string // URL of the image to compress
outputFormat?: "image/webp" | "image/jpeg" | "image/jpg" | "image/png" // Optional output format
}
}
compress_local_image
{
options: {
imagePath: string // Absolute path to the local image file
outputPath?: string // Optional absolute path for the compressed output image
outputFormat?: "image/webp" | "image/jpeg" | "image/jpg" | "image/png" // Optional output format
}
}
figma
{
options: {
figmaUrl: string // URL of the Figma file to fetch image links from
}
}
技术实现
该项目基于以下库构建:
- probe-image-size - 用于检测图像尺寸
- tinify - 通过 TinyPNG API 进行图像压缩
- figma-api - 用于从 Figma API 获取图像链接
环境变量
TINIFY_API_KEY- 用于图像压缩功能。从 TinyPNG 获取您的 API 密钥FIGMA_API_TOKEN- 用于从 Figma API 获取图像链接。从 Figma 获取您的 API 令牌
许可证
MIT