Install
$ agentstack add mcp-crper-py-image-compress-mcp ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
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.FastMCP - Local-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
Installation
Requirements:
- Python
3.10+ uv
Install:
git clone https://github.com/crper/py-image-compress-mcp.git
cd py-image-compress-mcp
uv sync
Quick Start
Run the local MCP server:
uv run py-image-compress-mcp
Or run the module directly:
uv run python -m py_image_compress_mcp
Inspect with the official MCP dev tool:
uv run mcp dev src/py_image_compress_mcp/mcp_server.py
Install into an MCP desktop client with the official CLI:
uv run mcp install src/py_image_compress_mcp/mcp_server.py
MCP 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-mcp
Check the registered config:
codex mcp get py-image-compress-local
Claude 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
- [CONTRIBUTING.md](CONTRIBUTING.md)
- [PYPIRELEASE.md](PYPIRELEASE.md)
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 examples
Run the remaining example script directly when needed:
uv run python examples/mcp_usage.py
Optional 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-e2e
Quick local validation:
uv run ruff check .
uv run mypy src tests
uv run pytest -q
Benchmarks
Run:
uv run python scripts/benchmark.py
The benchmark covers:
- metadata extraction on
public/images/3.jpg - single-image compression on
public/images/3.jpg - batch compression on
public/images - one extra real PNG from
~/Downloadswhen available
Project Notes
- Transport:
stdio - SDK: official
mcp[cli] - Server entry: [src/pyimagecompressmcp/mcpserver.py](/Users/linqunhe/code/self-github/projects/py-image-compress-mcp/src/pyimagecompressmcp/mcpserver.py)
License
MIT
Source & license
This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: crper
- Source: crper/py-image-compress-mcp
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.