py-image-compress-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@py-image-compress-mcp compress all images in photos/ to WEBP at quality 80"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
py-image-compress-mcp
Image compression and image metadata inspection over the official Python MCP SDK.
This project exposes a small local MCP server for desktop agents and coding tools. It keeps the MCP surface intentionally small:
compress_universal: compress a file, convert formats, or batch-process a directoryget_image_info: inspect dimensions, transparency, EXIF, ICC, and lightweight/full analysis
The server is designed for local stdio use and follows the official Python MCP stack via mcp[cli].
Why this project
Official Python MCP SDK:
mcp.server.fastmcp.FastMCPLocal-first: optimized for Codex, Claude Desktop, and other MCP desktop clients
Small API surface: two tools cover the main workflows
Safe output behavior: writes temp files first, then replaces the final output only when valid
Stable batch behavior: deterministic file discovery and ordered batch results
Conservative same-format behavior: skips likely negative recompression instead of wasting time re-encoding
Fast hot path: compression uses lightweight analysis instead of full metadata extraction
Related MCP server: pictor-mcp
Installation
Requirements:
Python
3.10+
Install:
git clone https://github.com/crper/py-image-compress-mcp.git
cd py-image-compress-mcp
uv syncQuick Start
Run the local MCP server:
uv run py-image-compress-mcpOr run the module directly:
uv run python -m py_image_compress_mcpInspect with the official MCP dev tool:
uv run mcp dev src/py_image_compress_mcp/mcp_server.pyInstall into an MCP desktop client with the official CLI:
uv run mcp install src/py_image_compress_mcp/mcp_server.pyMCP Tools
compress_universal
Compress one file, convert one file into multiple formats, or batch-process a directory.
Parameters:
input_path: file or directory pathoutput_path: optional output file or output directoryformats:None, a single format string, or a list of formatsquality:1-100;Nonekeeps lossless modemax_width,max_height: optional resize limitsrecursive: recurse into subdirectories in directory mode
Typical examples:
compress_universal("photo.jpg")compress_universal("photo.jpg", formats="WEBP", quality=82)compress_universal("photos/", output_path="compressed/", formats="WEBP", quality=80)compress_universal("photo.png", output_path="out/", formats=["WEBP", "JPEG", "PNG"], quality=80)
Behavior notes:
compress_universalmay short-circuit some same-format lossy requests such asJPEG -> JPEGorWEBP -> WEBPwhen the engine predicts a likely negative optimization.In that case the server still returns
success: true, copies the original bytes to the output path, and marks the file result withformat_used: "SKIPPED".For MCP callers, the skip reason is exposed in the structured result via
skipped: trueand a human-readablenotefield.The top-level
errorfield is reserved for real failures and staysnullfor successful skips.
get_image_info
Inspect image metadata and analysis with three response levels. The default level is summary.
Parameters:
input_path: image pathdetail:basic,summary, orfullinclude_histogram: optional overrideinclude_analysis: optional override
Detail levels:
basic: dimensions, file size, transparency, orientationsummary: default;basicplus EXIF / ICC / complexityfull:summaryplus histogram data
Python Usage
The Python-facing API is intentionally smaller than before. Create an ImageCompressor explicitly.
from py_image_compress_mcp import ImageCompressor
compressor = ImageCompressor()
result = compressor.compress_universal(
input_path="photo.jpg",
output="photo.webp",
formats="WEBP",
quality=82,
)
if result["success"]:
print(result["result"].get_summary())For the Python API, a skipped same-format recompression still returns success=True. Inspect result["result"].skipped and result["result"].note if you need to distinguish a true re-encode from a conservative no-op copy.
Direct single-file APIs are still available when you need more control:
from py_image_compress_mcp import ImageCompressor
compressor = ImageCompressor(max_workers=4)
single = compressor.compress_image("photo.jpg", output_dir="out", quality=80, format="JPEG")
multi = compressor.compress_multi_format("photo.jpg", "out", ["JPEG", "WEBP"], quality=80)Codex App / Codex CLI
Add the server as a local MCP server:
codex mcp add py-image-compress-local -- \
uv run --project /absolute/path/to/py-image-compress-mcp py-image-compress-mcpCheck the registered config:
codex mcp get py-image-compress-localClaude Desktop
Example configuration:
{
"mcpServers": {
"py-image-compress": {
"command": "uv",
"args": [
"run",
"--project",
"/absolute/path/to/py-image-compress-mcp",
"py-image-compress-mcp"
]
}
}
}More Docs
Upgrade Notes
Recent API cleanup further narrowed the public surface:
from py_image_compress_mcp import compress_universalwas removedfrom py_image_compress_mcp import BatchResult,CompressionResult, andMultiFormatResultwere removedpy_image_compress_mcp.mcp_server.create_serverwas removedbuild_config()was removed frompy_image_compress_mcp.engine.config
Use ImageCompressor() directly instead. The package root now guarantees only ImageCompressor and __version__.
Internal helper modules and re-exports under py_image_compress_mcp.* should be treated as private implementation details.
Development
Common commands:
make dev
make test
make typecheck
make benchmark
make examplesRun the remaining example script directly when needed:
uv run python examples/mcp_usage.pyOptional MCP smoke test:
# Use a directory that contains at least 5 images, including 3 PNG files.
uv run python scripts/mcp_e2e_test.py --source-dir ~/Downloads --output-dir tmp/mcp-e2eQuick local validation:
uv run ruff check .
uv run mypy src tests
uv run pytest -qBenchmarks
Run:
uv run python scripts/benchmark.pyThe benchmark covers:
metadata extraction on
public/images/3.jpgsingle-image compression on
public/images/3.jpgbatch compression on
public/imagesone extra real PNG from
~/Downloadswhen available
Project Notes
Transport:
stdioSDK: official
mcp[cli]Server entry: src/py_image_compress_mcp/mcp_server.py
License
MIT
Available Tools
2 toolscompress_universalB
压缩图片或批量处理目录。
支持单文件压缩、单文件多格式输出、格式转换和目录批量压缩。 返回统一的结构化结果,包含输出路径、压缩比例、节省空间和错误信息。
Inputs: input_path (required), formats, quality, max_width, +3 more. Returns: object
get_image_infoBRead-onlyIdempotent
读取图片元数据和分析信息。
`basic` 返回基础尺寸与透明度信息。
`summary` 额外返回 EXIF、ICC 和复杂度信息。
`full` 再额外返回完整直方图数据。
Inputs: input_path (required), detail, include_analysis, include_histogram. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The two tools have clearly distinct roles: one performs compression/format conversion (including batch directory runs), the other only reads metadata and analysis. There is no realistic scenario where an agent would confuse which to call, and the mode parameter on get_image_info is additive rather than overlapping with compression.
Both names follow the same snake_case verb_noun convention (compress_*, get_*), which is predictable and readable. The only weak spot is the vague modifier 'universal' in compress_universal, which hints at behavior rather than a resource but does not break the pattern.
Two tools is thin for a server, even a narrowly scoped one; the compression surface is compressed into a single multi-mode tool rather than exposing distinct operations. It is defensible given the single-purpose scope, but sits at the borderline of under-scoped sets.
The core lifecycle is covered: inspect an image, then compress/convert it, with batch directory processing and structured error/ratio reporting. Minor gaps remain (e.g. no output verification/cleanup or preview/quality-estimation step before a long batch run), but agents can work around these.
Maintenance
Related MCP Connectors
Convert images to PNG, JPEG, WebP, or AVIF through one public remote MCP tool.
Image processing over MCP: compress and split images, generate images and QR codes.
Image toolkit: resize, compress, crop, watermark, convert, rotate, EXIF read/strip.
Screenshots, PDFs, image editing, QR codes, email validation and more through one hosted MCP server.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables local batch image preparation for the web via MCP, including compression, resizing, metadata stripping, thumbnails, and favicon generation.23 npmMIT
- AlicenseAqualityBmaintenanceEnables MCP clients to inspect, convert, resize, compress, crop, rotate, watermark, background-remove, and batch-process images with secure path confinement and result verification.14MIT
- AlicenseNot gradedqualityBmaintenanceEnables local image processing through ImageMagick, letting MCP clients read image metadata, resize, convert between formats, crop, and rotate image files entirely on the host with no network calls.55 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents and MCP clients to generate, edit, and post-process images directly into a project, with text-to-image, instruction-based editing with masks and reference images, plus local resize, crop, and format conversion and dimension inspection tools.43 npm1MIT