Skip to content

feat: optimize_image tool (local compression, no API key), 0.4.0 - #17

Merged
facundofarias merged 1 commit into
mainfrom
feat/optimize-image
Nov 6, 2026
Merged

facundofarias merged 1 commit into
mainfrom
feat/optimize-image

Conversation

@facundofarias

Copy link
Copy Markdown
Member

What

New optimize_image tool for the local stdio MCP: compress, resize and convert a local image file on the user's machine. No API key, nothing uploaded. Mirrors pixelvault optimize in pixelvault-cli 0.14.0 (spec: docs/specs/optimize-command.md in pixelvault-dev/pixelvault). Local server only: the hosted MCP can't read the user's disk (it already has transform_image and the upload's optimized_url).

Inputs: path, format (keep|webp|avif|jpg|png), max_width/max_height, quality, keep_metadata, output_path | in_place, dry_run. Returns {input, output, status, reason, input_bytes, output_bytes, saved_percent, width, height}.

Safety

Default writes <name>.optimized.<ext> beside the original (original untouched); refuses to overwrite an existing file other than *.optimized.*; refuses symlinks (in place and as destination); atomic temp-file + rename writes; decode limits (100 MP / 100 MB); corrupt files return a structured error; never writes a bigger file; idempotent re-runs. EXIF orientation is applied before metadata is stripped.

Dependencies

sharp is an optionalDependency (external in tsup, loaded lazily). If it can't load, optimize_image returns sharp_unavailable with the reason and every other tool still works. The core (src/optimize-core.ts) is a copy of the CLI's src/lib/optimize.ts; keep them in sync (a shared package is a possible follow-up).

Testing

8 tests against real sharp (writes beside, webp+resize, idempotent second run, dry-run, in-place keeps .jpeg, no-overwrite, symlinks, input validation) plus the existing 13 pass; tsc --noEmit clean. Also ran the built server with a real MCP stdio client: tool listed, 4.1 MB PNG -> 72 KB WebP at 1600 px, missing file returns a structured not_found.

Release

0.4.0 is bumped but not published. This package's publish previously failed with an NPM_TOKEN E404 (0.2.0/0.3.0 are not on npm), so that needs sorting before tagging.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tde8opdomzAwwCkmME3ePL

Compress/resize/convert a LOCAL image file with sharp (optional dependency, loaded
lazily; a structured sharp_unavailable error if it can't load). Same pipeline as
`pixelvault optimize` in pixelvault-cli: orientation applied before metadata is
stripped, never writes a bigger file, idempotent, atomic writes, refuses to overwrite
unrelated files or write through symlinks. Local stdio server only: the hosted MCP
cannot read the user's disk.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tde8opdomzAwwCkmME3ePL
@facundofarias
facundofarias merged commit f1def87 into main Nov 6, 2026
1 check passed
@facundofarias
facundofarias deleted the feat/optimize-image branch November 6, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant