# MCP server

AlphaQuantize includes a Model Context Protocol (MCP) server, so AI agents such as Claude, ChatGPT and Codex, Cursor and GitHub Copilot can inspect images and make smaller copies of them on your computer, with the same engine as the app. Nothing is uploaded: the server runs locally, alongside the agent.

## What an agent can do

- **Look at an image:** its format, size in pixels and bytes, whether it has transparency, its DPI, and how many distinct colors it uses.
- **Make a smaller PNG that keeps its transparency:** quantize it to a palette of 2 to 256 colors (the pngquant engine, libimagequant), posterize it, smooth flat areas (blurizer) or apply a lossy filter.
- **Convert to WebP or AVIF,** lossless or lossy, at a chosen quality.
- **Resize and trim:** scale to a width or height (keeping the aspect ratio), or crop away fully transparent edges.
- **Work through many files:** an agent can call the tools once per image, for example to shrink every PNG in a folder, then report the savings.

Every copy is written beside the source as `NAME-optimized.EXT`, or to a path the agent chooses. Existing files are never overwritten unless the agent asks to, and the result says when a copy came out no smaller than the original.

## Turn it on

1. Install AlphaQuantize from [alphapng.app](https://alphapng.app/#download) and open it once.
2. Open **Settings → MCP** and turn on **Allow AI tools to use AlphaQuantize**.
3. Under **Add to AI Tools**, click **Add** next to each tool you use, then restart that tool.

Settings → MCP can add AlphaQuantize to these tools in one click (it edits only their `alphaquantize` entry, keeps comments in their config, and backs the file up first):

| AI tool | Config file it edits |
| --- | --- |
| Claude Desktop | `claude_desktop_config.json` (Claude's app-data folder) |
| Claude Code | `~/.claude.json` (every project) |
| ChatGPT desktop and Codex | `~/.codex/config.toml` (shared by the ChatGPT desktop app, the Codex CLI and its IDE extension) |
| Cursor | `~/.cursor/mcp.json` |
| VS Code (GitHub Copilot agent mode) | `Code/User/mcp.json` |
| Windsurf | `~/.codeium/windsurf/mcp_config.json` |
| Gemini CLI | `~/.gemini/settings.json` |
| Antigravity | `~/.gemini/config/mcp_config.json` |
| Zed | `~/.config/zed/settings.json` (`context_servers`) |

ChatGPT's web and phone apps only connect to remote servers, so use the ChatGPT desktop app.

## Add it by hand

The server is the app itself, started with `--mcp`. It speaks MCP over standard input and output, opens no window, and stops when the agent disconnects. **Settings → MCP → Other clients** shows the exact command for your installation, ready to copy. Usually it is:

| System | Command |
| --- | --- |
| macOS | `/Applications/AlphaQuantize.app/Contents/MacOS/alphaquantize --mcp` |
| Windows | `alphaquantize.exe --mcp`, in the folder AlphaQuantize was installed to (for the default per-user install, under `%LOCALAPPDATA%`) |
| Linux (.deb) | `/usr/bin/alphaquantize --mcp` |
| Linux (AppImage) | the AppImage's own path, then `--mcp` |

Most clients take this JSON, under `mcpServers` in their config:

```json
{
  "mcpServers": {
    "alphaquantize": {
      "command": "/Applications/AlphaQuantize.app/Contents/MacOS/alphaquantize",
      "args": ["--mcp"]
    }
  }
}
```

Claude Code, from a terminal:

```sh
claude mcp add --scope user alphaquantize -- /Applications/AlphaQuantize.app/Contents/MacOS/alphaquantize --mcp
```

Codex and the ChatGPT desktop app (`~/.codex/config.toml`):

```toml
[mcp_servers.alphaquantize]
command = '/Applications/AlphaQuantize.app/Contents/MacOS/alphaquantize'
args = ["--mcp"]
```

VS Code (`mcp.json`) uses `servers`, with a type:

```json
{
  "servers": {
    "alphaquantize": { "type": "stdio", "command": "/Applications/AlphaQuantize.app/Contents/MacOS/alphaquantize", "args": ["--mcp"] }
  }
}
```

Zed (`settings.json`) calls them `context_servers`:

```json
{
  "context_servers": {
    "alphaquantize": { "command": "/Applications/AlphaQuantize.app/Contents/MacOS/alphaquantize", "args": ["--mcp"] }
  }
}
```

## Tools

### image_info

Size, format, transparency, DPI and number of distinct colors of an image file: PNG, JPEG, GIF, WebP, BMP and TIFF, plus HEIC and AVIF where the system can decode them.

| Argument | Type | Description |
| --- | --- | --- |
| `path` | string, required | Absolute path of the image. |

Returns `path`, `format`, `width`, `height`, `bytes`, `hasAlpha`, `dpi` (or null) and `colors`.

### compress_image

Makes a smaller copy of an image, keeping its transparency, and saves it as PNG, WebP or AVIF. Writes beside the source as `NAME-optimized.EXT` unless `output` is given, and never overwrites an existing file unless `overwrite` is true. Options left out use the app's built-in defaults.

| Argument | Type and default | Description |
| --- | --- | --- |
| `path` | string, required | Absolute path of the source image. |
| `output` | string | Absolute path to write. Default: beside the source, `NAME-optimized.EXT`. |
| `overwrite` | boolean, `false` | Replace `output` if it exists (including the source itself). |
| `format` | `png`, `webp` or `avif`; `png` | File format to save. |
| `method` | `pngquant`, `posterize`, `blurize` or `lossy`; `pngquant` | pngquant: a palette of up to `colors`; posterize: fewer levels per channel; blurize: smooths flat areas; lossy: a lossy filter that keeps PNG. |
| `colors` | 2–256, `256` | Palette size for pngquant, or how strong the other methods are (fewer means smaller). |
| `dither` | boolean, `true` | Dither the palette. |
| `dither_level` | 0–1, `1` | Dithering strength. |
| `min_quality` | 0–100, `0` | pngquant: fail instead of going below this quality (0 turns it off). |
| `speed` | 1–10, `4` | pngquant speed: 1 is slowest and best, 10 fastest. |
| `posterize_bits` | 0–4, `0` | pngquant: round off this many low bits per channel first (the posterize floor), for displays with fewer bits per channel. |
| `compression` | `fast`, `better` or `best`; `fast` | PNG compression effort (best uses Zopfli and is slow). |
| `webp_lossy` | boolean, `false` | WebP only: encode lossily with `quality` instead of losslessly from the method's pixels. |
| `quality` | 0–100, `80` | Quality for lossy WebP and AVIF. |
| `keep_dpi` | boolean, `true` | PNG: keep the source's DPI. |
| `trim` | boolean, `false` | Crop away fully transparent edges first. |
| `width` | integer | Resize to this width (keeps the aspect ratio unless `height` is also given). |
| `height` | integer | Resize to this height. |

Returns `output`, `format`, `width`, `height`, `originalBytes`, `outputBytes`, `savedPercent`, `colors` and `quality` (pngquant), `millis`, `larger` and `warning`. When the copy is no smaller than the source, `larger` is true and `warning` explains it; the copy is still saved, so the agent can tell you and suggest fewer colors or another method.

### Errors

Problems come back as tool errors the agent can read and act on, for example a relative path (``"`path` must be an absolute path"``), a missing file, an output that already exists, a result below `min_quality`, or the server being turned off.

## Example requests

- "How many colors does `~/Desktop/logo.png` use, and does it have transparency?"
- "Make a 64-color version of `~/Desktop/logo.png` and tell me how much smaller it is."
- "Shrink every PNG in `~/Projects/site/images` with AlphaQuantize, keep the originals, and give me a table of the savings."
- "Convert `hero.png` to a 1200-pixel-wide lossy WebP at quality 80."
- "Trim the transparent edges of `icon.png` and save it as `icon-trimmed.png`."

## Control and privacy

- **Off switch:** Settings → MCP → **Allow AI tools to use AlphaQuantize**. When it's off, agents can still start the server, but every tool call is refused with a message saying so. It takes effect immediately, without restarting the agent.
- **Activity:** every request is logged on your computer: when, which app (the name it gave and the program that started the server), the tool, its arguments and what happened. Open it from **Settings → MCP → Activity…** or the **MCP** box in the status bar, which flashes on each call. The log is `mcp-log.jsonl` in AlphaQuantize's settings folder and is never sent anywhere.
- **Local only:** the server reads and writes files on your computer and makes no network requests. Paths must be absolute.

## Protocol details

- Transport: standard input and output (stdio), newline-delimited JSON-RPC 2.0.
- MCP versions: 2025-06-18, 2025-03-26 and 2024-11-05.
- Capabilities: tools (`image_info`, `compress_image`). No resources or prompts.
- Server name: `alphaquantize`.
