Image Dimensions MCP server

Retrieves image dimensions from URLs and local files with optional compression capabilities through the Tinify API for image analysis and processing tasks.
Back to servers
Setup instructions
Provider
kshern
Release date
Mar 12, 2025
Language
TypeScript
Stats
6 stars

The Image Tools MCP service enables you to retrieve image dimensions and compress images, supporting both URL-based and local file sources. It provides a simple way to work with images through the Model Context Protocol.

Installation

Prerequisites

  • Node.js installed on your system
  • A TinyPNG API key for compression functionality (available from TinyPNG developers page)

Installing the Service

Install the package using npm:

npm install image-tools-mcp

Configuration

To use the image compression features, you need to set your TinyPNG API key:

export TINIFY_API_KEY="your_tinify_api_key"

Using the Service

Available Functions

The MCP service provides four main functions:

  • get_image_size - Retrieve dimensions of remote images
  • get_local_image_size - Retrieve dimensions of local images
  • compress_image_from_url - Compress remote images using TinyPNG
  • compress_local_image - Compress local images using TinyPNG

Integration with Claude Desktop

  1. Install Claude Desktop from claude.ai/download
  2. 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>"
      }
    }
  }
}
  1. Restart Claude Desktop
  2. You can now ask Claude to:
    • Get image dimensions: "Can you tell me the dimensions of this image: https://example.com/image.jpg"
    • Compress an image from URL: "Can you compress this image: https://example.com/image.jpg"
    • Compress a local image: "Can you compress this image: D:/path/to/image.png"
    • Compress images in a folder: "Can you compress this folder: D:/imageFolder"

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

Function Options and Return Values

Getting Image Dimensions

From URL

// Function: get_image_size
// Options:
{
  options: {
    imageUrl: string // URL of the image to retrieve dimensions for
  }
}

// Return value example:
{ 
  width: 800, 
  height: 600, 
  type: "jpg", 
  mime: "image/jpeg" 
}

From Local File

// Function: get_local_image_size
// Options:
{
  options: {
    imagePath: string // Absolute path to the local image file
  }
}

// Return value example:
{ 
  width: 1024, 
  height: 768, 
  type: "png", 
  mime: "image/png", 
  path: "D:/path/to/image.png" 
}

Compressing Images

From URL

// Function: compress_image_from_url
// Options:
{
  options: {
    imageUrl: string, // URL of the image to compress
    outputFormat?: "image/webp" | "image/jpeg" | "image/jpg" | "image/png" // Optional output format
  }
}

// Return value example:
{ 
  originalSize: 102400, 
  compressedSize: 51200, 
  compressionRatio: "50.00%", 
  tempFilePath: "/tmp/compressed_1615456789.webp", 
  format: "webp" 
}

From Local File

// Function: compress_local_image
// Options:
{
  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
  }
}

// Return value example:
{ 
  originalSize: 102400, 
  compressedSize: 51200, 
  compressionRatio: "50.00%", 
  outputPath: "D:/path/to/compressed.webp", 
  format: "webp" 
}

Format Conversion

When compressing images, you can optionally convert them to different formats:

  • WebP: Specify "image/webp" as the outputFormat
  • JPEG: Specify "image/jpeg" or "image/jpg" as the outputFormat
  • PNG: Specify "image/png" as the outputFormat

If no output format is specified, the image will be compressed while maintaining its original format.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "image-tools" '{"command":"npx","args":["image-tools-mcp"],"env":{"TINIFY_API_KEY":"<YOUR_TINIFY_API_KEY>"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "image-tools": {
            "command": "npx",
            "args": [
                "image-tools-mcp"
            ],
            "env": {
                "TINIFY_API_KEY": "<YOUR_TINIFY_API_KEY>"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "image-tools": {
            "command": "npx",
            "args": [
                "image-tools-mcp"
            ],
            "env": {
                "TINIFY_API_KEY": "<YOUR_TINIFY_API_KEY>"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later