Cover image
Try Now
2025-04-13

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

3 years

Works with Finder

1

Github Watches

1

Github Forks

2

Github Stars

Image Tools MCP

A Model Context Protocol (MCP) service for retrieving image dimensions and compressing images, supporting both URL and local file sources.

中文文档

Features

  • Retrieve image dimensions from URLs
  • Get image dimensions from local files
  • Compress images from URLs using TinyPNG API
  • Compress local images using TinyPNG API
  • Convert images to different formats (webp, jpeg/jpg, png)
  • Returns width, height, type, MIME type, and compression information

Example Results

Example Result 1 Example Result 2

download from figma url and compress Example Result 3

Usage

Using as an MCP Service

This service provides five tool functions:

  1. get_image_size - Get dimensions of remote images
  2. get_local_image_size - Get dimensions of local images
  3. compress_image_from_url - Compress remote images using TinyPNG API
  4. compress_local_image - Compress local images using TinyPNG API
  5. figma - Fetch image links from Figma API and compress them using TinyPNG API

Client Integration

To use this MCP service, you need to connect to it from an MCP client. Here are examples of how to integrate with different clients:

Using with Claude Desktop

  1. Install Claude Desktop from claude.ai/download
  2. Get TinyPNG API key: Visit TinyPNG and get your API key
  3. Configure Claude Desktop to use this MCP server by editing the configuration file:
{
  "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. Restart Claude Desktop
  2. Ask Claude to get image dimensions: "Can you tell me the dimensions of this image: https://example.com/image.jpg"
  3. Ask Claude to compress an image: "Can you compress this image: https://example.com/image.jpg"
  4. Ask Claude to compress a local image: "Can you compress this image: D:/path/to/image.png"
  5. Ask Claude to compress a local image folder: "Can you compress this folder: D:/imageFolder"
  6. Ask Claude to fetch image links from Figma API: "Can you fetch image links from Figma API: https://www.figma.com/file/XXXXXXX"

Using with MCP Client Library

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
  }
}

Technical Implementation

This project is built on the following libraries:

Environment Variables

  • TINIFY_API_KEY - Required for image compression functionality. Get your API key from TinyPNG
    • When not provided, the compression tools (compress_image_from_url and compress_local_image) will not be registered
  • FIGMA_API_TOKEN - Required for fetching image links from Figma API. Get your API token from Figma
    • When not provided, the Figma tool (figma) will not be registered

Note: The basic image dimension tools (get_image_size and get_local_image_size) are always available regardless of API keys.

License

MIT

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Beniyam Berhanu
  • Therapist adept at identifying core issues and offering practical advice with images.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • OffchainLabs
  • 进行以太坊的实施

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

    Reviews

    4 (1)
    Avatar
    user_WN8sZJwi
    2025-04-18

    As a dedicated user of image-tools-mcp, I find it an essential tool for managing and processing images efficiently. The intuitive design and powerful features make it a standout in its category. Kudos to kshern for developing such a robust application. Highly recommend checking it out for your image processing needs!