svg-studio-mcp-server

v1.0.1
svg-studio-mcp-server Checked 2 days ago Published 22 days ago

MCP server for high-quality image vectorization using svg-studio's tuned settings

High-quality image vectorization MCP server preserving svg-studio's carefully tuned settings. ✅ High-Quality Vectorization - Proper luminance calculation (ITU-R BT.601: 0.299R + 0.587G + 0.114B) - Smart alpha transparency handling (transparent pixels = white background) - 10px padding to prevent edge clipping and corner rounding artifacts - Optimized Potrace parameters: - alphamax: 1.0 - Preserves sharp 90-degree corners - turdsize: 2 - Removes tiny speckles - opttolerance: 0.2 - Curve optimization - turnpolicy: minority - High-quality tracing policy ✅ Theme-Aware Output - Replaces fixed…

Summary extracted from the README.

SVG Studio MCP Server

High-quality image vectorization MCP server preserving svg-studio's carefully tuned settings.

Features

✅ High-Quality Vectorization

  • Proper luminance calculation (ITU-R BT.601: 0.299R + 0.587G + 0.114B)
  • Smart alpha transparency handling (transparent pixels = white background)
  • 10px padding to prevent edge clipping and corner rounding artifacts
  • Optimized Potrace parameters:
    • alphamax: 1.0 - Preserves sharp 90-degree corners
    • turdsize: 2 - Removes tiny speckles
    • opttolerance: 0.2 - Curve optimization
    • turnpolicy: minority - High-quality tracing policy

✅ Theme-Aware Output

  • Replaces fixed black fill with currentColor for CSS theming
  • Responsive SVG (100% width/height)

✅ Agent-Friendly

  • Three MCP tools: vectorize_image, batch_vectorize and vectorize_multicolour_image
  • CLI and programmatic usage
  • Batch processing with parallel execution

Installation

From a clone of this repository, build the server in the mcp-server directory:

cd mcp-server
npm install && npm run build

The local site’s Install page provides the packaged server and exact commands for its current address. Install that package in your project and configure node_modules/svg-studio-mcp-server/dist/index.js as a stdio MCP server. The collection registry and installable skill use the official shadcn MCP integration.

Once the package is published to npm, npx -y svg-studio-mcp-server can start it directly. The local package works before publication.

MCP Tools

Relative paths resolve against the server's working directory; ~ is not expanded, so give absolute paths when in doubt.

Multicolour artwork

vectorize_multicolour_image accepts image_path, optional colours (2–64, default 16), remove_background (default false), and output_path. It uses deterministic weighted k-means over a 5-bit colour histogram, then traces overlapping colour masks after 3×3 label-majority cleanup into at most one simplified compound path per palette entry. Paths use explicit hex fills. The original dimensions form the viewBox. Existing monochrome tools are unchanged.

import { vectorizeMulticolourImage } from './dist/vectorize.js';
const svg = await vectorizeMulticolourImage('character.png', {
  colours: 24,
  removeBackground: true,
});

Background removal floods near-white pixels (all channels ≥245) from the canvas edge. Enclosed white features remain opaque. Existing alpha is a binary cutout at 128. Palette fitting samples colour interiors rather than antialias bands. Potrace removes areas ≤8 px and optimises curves at 0.6 px tolerance. This is for flat artwork, not continuous-tone photos or translucent art. Quantisation and tracing are approximations: compare the source and rendered SVG at the intended sizes. npm test builds and checks fixture render differences, transparency, background removal, old monochrome behavior and the real MCP tool.

1. vectorize_image

Convert a single raster image to SVG.

Parameters:

  • image_path (required): Path to input image (PNG, JPG, WebP, etc.)
  • threshold (optional): Black/white threshold 0-100 (default: 60)
    • Lower = more black, higher = more white
  • output_path (optional): Where to save SVG. If omitted, returns content only.

Example usage by agents:

Use vectorize_image tool with:
- image_path: "./icon.png"
- threshold: 60
- output_path: "./icon.svg"

2. batch_vectorize

Vectorize multiple images at once (parallel processing).

Parameters:

  • image_paths (required): Array of image paths
  • threshold (optional): Threshold for all images (default: 60)
  • output_dir (optional): Directory to save SVGs. If omitted, returns content only.

The server creates the requested directory. Same-named inputs and existing outputs receive numbered filenames; earlier files are preserved. The result reports each actual output path and any per-file error. Thresholds outside 0–100 and invalid paths return errors.

Example usage by agents:

Use batch_vectorize tool with:
- image_paths: ["./icons/icon1.png", "./icons/icon2.png"]
- threshold: 60
- output_dir: "./svgs"

CLI Usage

# Start the MCP server
node dist/index.js

# Or use npm script
npm start

Integration

Register the server with Claude Code:

claude mcp add svg-studio -- npx -y svg-studio-mcp-server

Or add it to an mcpServers configuration file (for example .mcp.json):

{
  "mcpServers": {
    "svg-studio": {
      "command": "npx",
      "args": ["-y", "svg-studio-mcp-server"]
    }
  }
}

Before the package is published, use node with the absolute path to your local mcp-server/dist/index.js as the command instead of npx.

Agents can then:

  1. Convert icons/logos to SVG
  2. Batch process image sets
  3. Get high-quality vector output matching the web app quality

Quality Settings

It shares the web app's Potrace approach but not every setting. The MCP server uses BT.601 luminance, treats alpha below 128 as white, uses fixed Potrace parameters and keeps the 10 px padding inside the viewBox; the web app (src/lib/vectorize.ts) uses BT.709 luminance, cuts alpha at 32, removes white backgrounds and drives Potrace from the smoothness slider. Its settings:

  • ✅ Proper luminance (not naive RGB averaging)
  • ✅ Alpha transparency → white background
  • ✅ 10px padding (prevents corner rounding)
  • ✅ Sharp corners preserved (alphamax=1.0)
  • ✅ Clean output (turdsize=2 removes noise)
  • ✅ Theme-aware (currentColor fill)
  • ✅ Responsive (100% dimensions)

Development

# Watch mode
npm run watch

# Build
npm run build

# Run without build
npm run dev

Output Example

Input: PNG icon (raster) Output: Clean SVG with:

  • fill="currentColor" (theme-aware)
  • width="100%" height="100%" (responsive)
  • Sharp corners preserved
  • No artifacts or noise
  • Optimized Bézier curves

Notes

  • Uses Node.js potrace library (same algorithm as web WASM version)
  • sharp for image preprocessing (equivalent to Canvas API in browser)
  • Parallel batch processing for efficiency