API & MCP
Everything a person can do on SVG Optimizer, a program or AI agent can do with the same inputs and get the identical result.
HTTP API
POST https://svgoptimizer.usefulweb.site/api/v1/calculate– run SVG OptimizerGET https://svgoptimizer.usefulweb.site/api/v1/tool– inputs, output schema, examples- OpenAPI 3.1: /openapi.json · /openapi.yaml
- Errors:
application/problem+json;422includes per-fielderrors.
SVG Optimizer
Optimises an SVG file in your choice of steps and shows how many bytes each one saved: removes comments, metadata and Inkscape/Illustrator editor data, hidden and empty elements, rounds numbers, rewrites path data in its shortest form and collapses whitespace. It also removes scripts, event handlers and external references, so the result is safe to embed.
| Field | Type | Default | Description |
|---|---|---|---|
svgFile | file | — | SVG file. An .svg or .svgz file, max 5 MB. Alternatively paste the SVG code below. |
svgText | textarea | — | Or paste SVG code |
precision | integer | 3 | Decimal places. Coordinates and lengths are rounded to this many decimals. 1–3 is usually invisible; transforms keep two more. |
minifyPaths | boolean | true | Minify path data (shortest relative/absolute commands) |
removeHidden | boolean | true | Remove hidden elements and unused definitions |
removeDimensions | boolean | false | Remove width/height (keep viewBox so the SVG scales responsively) |
Example request
Inkscape export with a script
curl -X POST https://svgoptimizer.usefulweb.site/api/v1/calculate -H 'content-type: application/json' -d '{"svgText":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!-- Created with Inkscape (http://www.inkscape.org/) -->\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" width=\"120.000000\" height=\"80.000000\" viewBox=\"0 0 120 80\" version=\"1.1\" onload=\"alert('hi')\">\n <sodipodi:namedview id=\"namedview1\" pagecolor=\"#ffffff\" inkscape:zoom=\"2.0\"/>\n <metadata id=\"metadata1\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"/></metadata>\n <script>alert('x')</script>\n <g inkscape:label=\"Layer 1\" inkscape:groupmode=\"layer\" id=\"layer1\">\n <rect x=\"10.0000001\" y=\"10.123456\" width=\"40.000000\" height=\"30.000000\" fill=\"#1652f0\" />\n <path d=\"M 60.000000 10.000000 L 110.000000 10.000000 L 110.000000 40.000000 L 60.000000 40.000000 Z\" fill=\"#f0a500\" />\n <circle cx=\"35.555555\" cy=\"60.444444\" r=\"12.0000\" fill=\"#0f8a5f\" style=\"display:none\" />\n <g></g>\n </g>\n</svg>\n","precision":2}'
Every result contains
inputs (normalised, defaults applied), summary, result (validated against the published schema), units, assumptions, sources, warnings, computedAt and links.
MCP (Model Context Protocol)
- Streamable HTTP endpoint:
https://svgoptimizer.usefulweb.site/mcp– protocol revisions 2026-07-28 (stateless) and 2025-11-25 / 2025-06-18 / 2025-03-26 (initialize handshake). - Tools:
svg_optimizer - Local stdio connector:
node src/mcp-stdio.ts --tool=svg-optimizer
{
"mcpServers": {
"svg-optimizer": { "type": "http", "url": "https://svgoptimizer.usefulweb.site/mcp" }
}
}