image-tools-mcp

image-tools-mcp

图像工具 MCP 是一个模型上下文协议 (MCP) 服务,它使用 TinyPNG API 从 URL 和本地文件中检索图像尺寸并压缩图像。它支持将图像转换为 webp、jpeg/jpg 和 png 等格式,并提供有关宽度、高度、类型和压缩的详细信息。

Category
访问服务器

Tools

get_image_size

Get the size of an image from URL

get_local_image_size

Get the size of a local image

compress_image_from_url

Compress a single image from URL using TinyPNG API (only supports image files, not folders)

compress_local_image

Compress a single local image file using TinyPNG API (only supports image files, not folders)

README

Image Tools MCP

一个用于检索图像尺寸和压缩图像的模型上下文协议 (MCP) 服务,支持 URL 和本地文件源。

功能特性

  • 从 URL 检索图像尺寸
  • 从本地文件获取图像尺寸
  • 使用 TinyPNG API 压缩来自 URL 的图像
  • 使用 TinyPNG API 压缩本地图像
  • 将图像转换为不同的格式 (webp, jpeg/jpg, png)
  • 返回宽度、高度、类型、MIME 类型和压缩信息

示例结果

示例结果 1 示例结果 2

从 figma url 下载并压缩 示例结果 3

用法

用作 MCP 服务

此服务提供五个工具功能:

  1. get_image_size - 获取远程图像的尺寸
  2. get_local_image_size - 获取本地图像的尺寸
  3. compress_image_from_url - 使用 TinyPNG API 压缩远程图像
  4. compress_local_image - 使用 TinyPNG API 压缩本地图像
  5. figma - 从 Figma API 获取图像链接并使用 TinyPNG API 压缩它们

客户端集成

要使用此 MCP 服务,您需要从 MCP 客户端连接到它。 以下是如何与不同客户端集成的示例:

与 Claude Desktop 一起使用

  1. claude.ai/download 安装 Claude Desktop
  2. 获取 TinyPNG API 密钥:访问 TinyPNG 并获取您的 API 密钥
  3. 通过编辑配置文件来配置 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>"
      }
    }
  }
}
  1. 重新启动 Claude Desktop
  2. 要求 Claude 获取图像尺寸:“你能告诉我这张图片的尺寸吗:https://example.com/image.jpg”
  3. 要求 Claude 压缩图像:“你能压缩这张图片吗:https://example.com/image.jpg”
  4. 要求 Claude 压缩本地图像:“你能压缩这张图片吗:D:/path/to/image.png”
  5. 要求 Claude 压缩本地图像文件夹:“你能压缩这个文件夹吗:D:/imageFolder”
  6. 要求 Claude 从 Figma API 获取图像链接:“你能从 Figma API 获取图像链接吗:https://www.figma.com/file/XXXXXXX”

与 MCP 客户端库一起使用

import { McpClient } from "@modelcontextprotocol/client";

// 初始化客户端
const client = new McpClient({
  transport: "stdio" // 或其他传输选项
});

// 连接到服务器
await client.connect();

// 从 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" }

// 从本地文件获取图像尺寸
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" }

// 从 URL 压缩图像
const compressUrlResult = await client.callTool("compress_image_from_url", {
  options: {
    imageUrl: "https://example.com/image.jpg",
    outputFormat: "webp" // 可选:转换为 webp, jpeg/jpg, 或 png
  }
});
console.log(JSON.parse(compressUrlResult.content[0].text));
// Output: { originalSize: 102400, compressedSize: 51200, compressionRatio: "50.00%", tempFilePath: "/tmp/compressed_1615456789.webp", format: "webp" }

// 压缩本地图像
const compressLocalResult = await client.callTool("compress_local_image", {
  options: {
    imagePath: "D:/path/to/image.png",
    outputPath: "D:/path/to/compressed.webp", // 可选
    outputFormat: "image/webp" // 可选:转换为 image/webp, image/jpeg, 或 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" }

// 从 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"] }

### 工具模式

#### get_image_size

```typescript
{
  options: {
    imageUrl: string // 要检索尺寸的图像的 URL
  }
}

get_local_image_size

{
  options: {
    imagePath: string // 本地图像文件的绝对路径
  }
}

compress_image_from_url

{
  options: {
    imageUrl: string // 要压缩的图像的 URL
    outputFormat?: "image/webp" | "image/jpeg" | "image/jpg" | "image/png" // 可选的输出格式
  }
}

compress_local_image

{
  options: {
    imagePath: string // 本地图像文件的绝对路径
    outputPath?: string // 压缩输出图像的可选绝对路径
    outputFormat?: "image/webp" | "image/jpeg" | "image/jpg" | "image/png" // 可选的输出格式
  }
}

figma

{
  options: {
    figmaUrl: string // 要从中获取图像链接的 Figma 文件的 URL
  }
}

技术实现

该项目构建在以下库之上:

环境变量

  • TINIFY_API_KEY - 图像压缩功能必需。 从 TinyPNG 获取您的 API 密钥
  • FIGMA_API_TOKEN - 从 Figma API 获取图像链接必需。 从 Figma 获取您的 API 令牌

许可证

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选