Skip to content

feat: MCP wrapper server for LLM tool integration #698

Description

@nagyonmarci

Summary

I'd like to propose adding a lightweight MCP (Model Context Protocol) wrapper server so LLMs like Claude can use imgcompress as a tool directly, without a human operating the UI.

Motivation

imgcompress is a capable image processing backend, but it currently only has a browser-based frontend as its client. With the rise of AI agents and LLM-driven workflows, there's a growing need for tools that can be invoked programmatically by models. An MCP server bridges that gap — it exposes the existing REST API as structured tools that any MCP-compatible LLM can call.

Proposed approach

  • Transport: stdio (the LLM client spawns the server as a local process — no new ports, no new attack surface)

  • Architecture: pure proxy — no business logic, no changes to the backend. All calls go through the existing REST API, exactly as the browser does

  • New dependencies: mcp[cli], httpx (Python, isolated in mcp/)

  • Structure:

    mcp/
      pyproject.toml    ← dependencies (mcp[cli], httpx)
      server.py         ← FastMCP server, 6 tools
    
  • Tools exposed:

    Tool Endpoint
    compress_images POST /api/compress
    remove_background POST /api/compress with use_rembg=true
    download_file GET /api/download
    download_all GET /api/download_all
    list_supported_formats GET /api/images_supported
    health_check GET /api/health/backend
  • Security model is unchanged: the LLM never touches the container directly. The REST API remains the only entry point — the MCP server is just a new client of it.

Example use cases

  • An AI coding agent generates a logo in SVG and immediately converts and compresses it — no human in the loop
  • Claude assembles a document and optimizes all images before exporting
  • Batch background removal from a single prompt: "remove the background from these 20 images"

What I have ready

I have a working implementation on my fork, tested end-to-end against a running imgcompress container. Claude Desktop picks it up automatically via the standard MCP connector config. I can open a PR if this direction sounds good to you.

Questions before opening a PR

  1. Is MCP integration something you'd want in the project?
  2. Should mcp/ live at the repo root, or would you prefer it under a contrib/ or integrations/ directory?
  3. Any preference on whether the mcp/ environment should use uv (consistent with the rest of the project) instead of plain pip?

Happy to adjust the approach based on your feedback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions