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.
Install the package using npm:
npm install image-tools-mcp
To use the image compression features, you need to set your TinyPNG API key:
export TINIFY_API_KEY="your_tinify_api_key"
The MCP service provides four main functions:
{
"mcpServers": {
"image-tools": {
"command": "npx",
"args": ["image-tools-mcp"],
"env": {
"TINIFY_API_KEY": "<YOUR_TINIFY_API_KEY>"
}
}
}
}
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: 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"
}
// 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"
}
// 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"
}
// 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"
}
When compressing images, you can optionally convert them to different formats:
"image/webp"
as the outputFormat
"image/jpeg"
or "image/jpg"
as the outputFormat
"image/png"
as the outputFormat
If no output format is specified, the image will be compressed while maintaining its original format.
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.
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.
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>"
}
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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