shotluma-design-mcp
# shotluma-design-mcp
A local, model-agnostic **design engine exposed over MCP**. Any MCP client (Codex, Claude Desktop, Claude Code, Cursor, Cline, Continue, Zed, …) can create a design project, import screenshots and logos, compose pages from layers, render them in a local headless browser, inspect real measurements, validate, and export exact-size PNG/ZIP plus a re-editable project.
**The AI makes the design decisions. The server renders deterministically. Original screenshots and logos are protected layers: they are never redrawn, re-encoded, stretched, cropped or covered.**
It is not an image generator and not a template picker. It calls no AI model, needs no API key, and uses no cloud service.

> Independent derivative of [Shotluma](https://github.com/realZachi/shotluma) (MIT). Not an official Shotluma product. See [NOTICE](NOTICE) and [docs/UPSTREAM_REVIEW.md](docs/UPSTREAM_REVIEW.md).
---
## Contents
- [Requirements](#requirements) · [Install & build](#install--build) · [Connect a client](#connect-an-mcp-client)
- [Tools](#mcp-tools) · [Workflow](#recommended-workflow) · [Example prompt](#example-prompt)
- [Project format](#design-project-format) · [Brand config](#brand-configuration) · [Device frames & corners](#device-frames-and-screen-corners)
- [Content protection](#how-content-protection-works) · [Privacy & image transfer](#privacy-and-image-transfer) · [Security](#security-model)
- [Fonts](#fonts) · [CLI](#cli) · [Configuration](#configuration) · [Troubleshooting](#troubleshooting) · [Development](#development) · [License](#license)
## Requirements
| | |
|---|---|
| Node.js | ≥ 20.10 (tested on 24.16) |
| Browser | Chromium-based, headless. `npx playwright-core install chromium`, or an installed Chrome/Edge/Chromium (auto-detected), or `SHOTLUMA_BROWSER_PATH` |
| OS | Windows verified; macOS/Linux supported by the code but **not verified** in this release (see [Known limitations](#known-limitations)) |
| Fonts | Installed system fonts or font files you import. CJK copy needs a CJK font (e.g. Microsoft YaHei, PingFang SC, Noto Sans CJK) |
## Install & build
```bash
git clone https://github.com/Aana11/shotluma-design-mcp.git
cd shotluma-design-mcp
npm install
npm run build
npx playwright-core install chromium # skip if Chrome/Edge is installed
node dist/cli.js doctor # checks browser, rendering and fonts
```
Once published to npm (not published yet — see [Publishing](#publishing)), `npx -y shotluma-design-mcp@latest` will work without cloning.
## Connect an MCP client
The server speaks MCP over **stdio**. Every client needs the same three things: `node`, the absolute path to `dist/cli.js`, and the directories the server may touch (`--allow <dir>`, repeatable). Without `--allow`, only the working directory the client starts it in is allowed. Clients that support MCP *roots* add their workspace roots automatically.
Replace `/abs/path/shotluma-design-mcp` and `/abs/path/work` below. On Windows use `C:\\path\\to\\...` with escaped backslashes in JSON, or forward slashes.
**Generic (`mcpServers` JSON — Claude Desktop, Cursor, and most clients)**
```json
{
"mcpServers": {
"shotluma-design": {
"command": "node",
"args": ["/abs/path/shotluma-design-mcp/dist/cli.js", "--allow", "/abs/path/work"]
}
}
}
```
After npm publication the same entry becomes `"command": "npx", "args": ["-y", "shotluma-design-mcp@latest", "--allow", "/abs/path/work"]` (on Windows some clients need `"command": "cmd", "args": ["/c", "npx", ...]`).
| Client | Where | Format |
|---|---|---|
| **Claude Desktop** | Settings → Developer → Edit Config (`claude_desktop_config.json`) | `mcpServers` JSON above; restart the app |
| **Claude Code** | `claude mcp add shotluma-design -- node /abs/path/shotluma-design-mcp/dist/cli.js --allow /abs/path/work` — or a project `.mcp.json` with the `mcpServers` JSON | CLI / JSON |
| **Cursor** | `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` (project) | `mcpServers` JSON |
| **Cline** | MCP Servers panel → Configure (`cline_mcp_settings.json`; CLI: `~/.cline/data/settings/cline_mcp_settings.json`) | `mcpServers` JSON; optional `"disabled": false`, `"autoApprove": []` (keep `render_preview` and `export_design` out of autoApprove) |
| **Codex** | `~/.codex/config.toml` or project `.codex/config.toml`, or `codex mcp add shotluma-design -- node … --allow …` | TOML, see below (key is `mcp_servers`, not `mcpServers`) |
| **Continue** | `config.yaml` (agent mode only) | YAML, see below |
| **Zed** | Settings → AI → MCP Servers → Add Local Server, or `settings.json` | `context_servers`, see below |
| **Other MCP clients** | any client that launches stdio servers | `command` + `args` as above |
Codex (`config.toml`):
```toml
[mcp_servers.shotluma-design]
command = "node"
args = ["/abs/path/shotluma-design-mcp/dist/cli.js", "--allow", "/abs/path/work"]
startup_timeout_sec = 30
```
Continue (`config.yaml`):
```yaml
mcpServers:
- name: shotluma-design
command: node
args:
- /abs/path/shotluma-design-mcp/dist/cli.js
- --allow
- /abs/path/work
```
Zed (`settings.json`):
```json
{
"context_servers": {
"shotluma-design": {
"command": "node",
"args": ["/abs/path/shotluma-design-mcp/dist/cli.js", "--allow", "/abs/path/work"],
"env": {}
}
}
}
```
Formats were checked against the clients' current documentation ([Codex](https://developers.openai.com/codex/mcp), [Continue](https://docs.continue.dev/customize/deep-dives/mcp), [Zed](https://zed.dev/docs/ai/mcp), [Cline](https://docs.cline.bot/mcp/mcp-overview)) at release time. Only the generic stdio protocol path was exercised by automated tests (official SDK client); individual client apps were not driven end-to-end.
## MCP tools
| Tool | Purpose |
|---|---|
| `create_project` | Create `design.json` + `assets/ previews/ exports/` with one or more canvases of any size; optional per-project brand (object or `brand.json` path). |
| `open_project` | Load and schema-validate a project; check every asset exists and matches its SHA-256; report recoverability. |
| `import_assets` | Copy files byte-for-byte (PNG, JPEG, WebP, GIF, SVG, TTF/OTF/WOFF/WOFF2) and record id, size, aspect, MIME, SHA-256, purpose (`screenshot`, `logo`, `image`, `background`, `decoration`, `font`) and protection. Never returns image bytes. |
| `list_layout_styles` | Optional composition starting points and device frames. |
| `generate_layout` | Pure-geometry layout variants (`centered`, `side`, `split`, `duo`, `multi`, `grid`, `stagger`, `tilted`, `auto`) returned as editable operations; optionally applied to a page. |
| `apply_operations` | Atomic batch of structured edits: pages, canvas, background, layers (add/update/remove/reorder/group/ungroup), text, frames, asset replacement, brand, protection grants. All-or-nothing. |
| `inspect_design` | Layer tree with browser-measured bounds, text lines/overflow, font usage, overlaps, screenshot display scale, asset status, issues. |
| `render_preview` | Same renderer as export. Writes PNGs to `previews/`, returns measurements/font report/issues. Image content only on request (see privacy). |
| `validate_design` | Errors / warnings / suggestions / info, including pixel-level protected-content verification. |
| `export_design` | Exact-size PNGs, ZIP, and/or a re-editable project copy, after the integrity gate. Never overwrites unless asked. |
Also: resource `shotluma://guidelines` (design guide), resource `shotluma://operations` (operation reference), prompt `design_workflow`, and server `instructions` for clients that show them.
## Recommended workflow
```
understand the request → create_project / open_project → import_assets
→ read brand + asset sizes → compose (generate_layout as a start, or free apply_operations)
→ render_preview → inspect_design / validate_design → targeted fixes → export_design
```
## Example prompt
> 使用 `~/work/shots` 目录中的三张应用截图,制作一张 1080×1920 的极简产品宣传图。自行设计构图、字体、背景及装饰,保留截图中的全部文字和 UI,不裁剪、不拉伸、不重新绘制截图。先生成预览并检查布局,修正问题后导出 PNG,同时保存可重新编辑的设计工程。
> Use the three app screenshots in `~/work/shots` to make a minimal 1080×1920 promo image. Choose the composition, type, background and decoration yourself. Keep every word and UI element of the screenshots: no cropping, stretching or redrawing. Preview and check the layout first, fix problems, then export a PNG and keep the editable project.
The seven designs in [`examples/showcase/`](examples/showcase) were produced exactly this way over MCP stdio by [`examples/run-showcase.ts`](examples/run-showcase.ts): single device (1080×1920), two devices side by side (1920×1080), three devices (1290×2796, started from `generate_layout`), landscape product intro with a browser frame (1920×1280), tablet with a 3D frame and Japanese copy (1080×1350), a three-page Chinese series with shared visual system (PNG + ZIP + project copy), and a free composition without presets (1200×1500).
## Design project format
```
project/
├── design.json complete re-editable design (schemaVersion 1)
├── assets/ imported files, byte-identical to the sources (as_<id>.<ext>)
├── previews/ render_preview output
└── exports/ export_design output (timestamped folders)
```
```jsonc
{
"schemaVersion": 1, "id": "pr_x1y2z3", "name": "Promo", "revision": 7,
"brand": null, // or a brand object (per project)
"assets": [{
"id": "as_ab12cd34", "name": "home.png", "file": "assets/as_ab12cd34.png",
"mime": "image/png", "width": 1080, "height": 2340, "aspectRatio": 0.461538,
"bytes": 203018, "sha256": "…", "purpose": "screenshot",
"protection": { "enabled": true, "grants": {} },
"edges": { "top": ["#f4f5f7", …], "bottom": […], "left": […], "right": […] }
}],
"pages": [{
"id": "pg_…", "name": "Hero", "width": 1080, "height": 1920,
"background": { "type": "solid", "color": "#F5F2EC" },
"layers": [
{ "id": "phone", "type": "device", "frame": "phone", "assetId": "as_ab12cd34",
"x": 245, "y": 610, "width": 590, "height": 1239.4, "rotation": 0, "opacity": 1,
"frameOptions": { "color": "#1B1B1D", "screenCorners": "auto", "buttons": true, "depth": 0 } },
{ "id": "headline", "type": "text", "text": "Every idea,\nin one place.",
"x": 80, "y": 236, "width": 920, "style": { "fontFamily": "Segoe UI, sans-serif", "fontSize": 96, "fontWeight": 800, "color": "#1A1A1A", "align": "center" } }
]
}],
"audit": [ { "at": "…", "action": "set_asset_protection", "detail": "…" } ]
}
```
- All coordinates are **canvas pixels** of their page; layer order = paint order.
- Layer types: `image`, `text` (with structured word `highlights`, optional box), `shape` (rect, ellipse, pill, triangle, diamond, star, burst, spark, blob, arch, ring, line, arrow, wave), `device`, `group` (children relative to the group).
- Fills are colors or linear/radial gradients; shadows, strokes, opacity, rotation, background patterns (dots, grid, diagonal, waves).
- Ids are stable; asset paths are relative, so a project folder can be moved anywhere and reopened.
- Writes are atomic (temp file + rename). Every batch increments `revision`; `expectedRevision` gives optimistic locking.
## Brand configuration
Optional, per project, never global. Pass an object or a path to a JSON file to `create_project`, or set it later with `{"op":"set_brand"}`:
```json
{
"name": "Example Product",
"colors": { "primary": "#2563EB", "background": "#FFFFFF", "text": "#171717" },
"fonts": { "heading": "sans-serif", "body": "sans-serif" },
"style": { "keywords": ["minimal", "clean"], "logoProtection": true, "screenshotProtection": true }
}
```
See [`examples/brand.example.json`](examples/brand.example.json). Without a brand, nothing is themed: the AI picks palette and type from the request and the screenshots (layout output uses neutral placeholders and says so).
## Device frames and screen corners
Frames are **program-drawn** (CSS/SVG). No bitmap device mockups, no brand-specific devices. `none`, `thin`, `phone`, `tablet`, `laptop`, `browser`, `window`; options: body `color`, `bezel`, `cornerRadius`, `screenRadius`, `buttons`, `depth` (3D edge), `chromeColor`, `addressText`, `screenColor`, `shadow`, and an authorized `perspective`.
The **screen always takes the screenshot's own aspect ratio**. Frames never force a ratio and never stretch.
Corners are concentric (body radius = display radius + bezel) and come in two modes:
| `screenCorners` | Result | Screenshot pixels |
|---|---|---|
| `auto` / `inset` (default) | Realistically rounded display. The screenshot sits just inside it (inset = r·(1−1/√2)), so its square corners fall within the rounded display. The thin band around it is painted with colors sampled from the screenshot's own edges, so the screen reads edge-to-edge. | **none cut** |
| `clip` | The screenshot itself is rounded (edge-to-edge marketing look). | corners cut; on protected screenshots capped at 3% of the shorter side unless the user grants `cornerRadius` |
## How content protection works
Protection is enforced by the data model and the renderer, not by prompt wording. Screenshots and logos are protected by default.
| Layer | Guarantee |
|---|---|
| Import | Bytes copied verbatim; SHA-256 of source before/after and of the copy must match; never decoded and re-encoded. SVGs with scripts, handlers, entities, `foreignObject` or external references are rejected, never rewritten. |
| Operations | Every batch is checked as a whole. Protected assets may only move, scale uniformly and change stacking order. `fill` stretch is impossible; crop/cover, rotation (including via parent groups), perspective, opacity < 1, and logos inside device screens are rejected unless a matching **grant** (with the user's quoted authorization, recorded in `audit`) exists. |
| Renderer | Assets are served to the browser only from the project, by id, with SHA-256 re-verified on every request (modified file → render refused). Original bytes go straight to Chromium; there is no JPEG/WebP intermediate. |
| Validation / export gate | Protected content cut by the canvas edge → error. Anything painted over it → error (geometric check plus pixel proof). **Pixel proof:** each protected layer is rendered in isolation with identical transforms; every fully opaque pixel of that reference must be identical in the final render, which catches overlapping layers *and* shadows cast onto a screenshot. |
| Source comparison | 1:1 at integer position → the exported region must equal the decoded file **exactly** (tested). Uniform scale → compared to a Lanczos resample by PSNR (resampling is expected; it is never called "identical"). Rotation/perspective → occlusion proof only. |
Three things are reported separately: (1) **file byte integrity** (SHA-256), (2) **rendered content fidelity** (occlusion proof and 1:1 equality), (3) **normal resampling** from scaling or transforms.
Grants (`rotation`, `perspective`, `crop`, `occlusion`, `cornerRadius`) are opt-in effects the user asked for:
```json
{ "op": "set_asset_protection", "assetId": "as_ab12cd34",
"grant": { "effect": "rotation", "authorization": "User: \"tilt the phone a little\"" } }
```
## Privacy and image transfer
- The server is local and uses stdio only. It opens no network port, sends no telemetry, and fetches no remote config.
- **A local MCP server does not mean the client's model is local.** Anything returned to the client may be uploaded to a remote model.
- `import_assets`, `inspect_design` and `validate_design` never return image bytes.
- `render_preview` writes PNGs to disk and returns **no image** by default.
- `returnImage: "layout"` returns a downscaled preview with protected screenshots/logos replaced by labelled placeholders.
- `returnImage: "full"` requires `userConsent` (the user's words). The consent is logged in the project's `audit`. Start the server with `--no-image-return` to disable image return completely.
- Clients that cannot receive images can work entirely from the structured measurements.
## Security model
- File access is limited to `--allow` directories (plus client roots). Paths are realpath-resolved, so symlinks/junctions pointing outside are refused. Project-internal references cannot escape the project (`..`, absolute and drive paths are rejected).
- Chromium runs headless in a fresh context per render. Every request except the renderer's private origin is aborted, and the page has a `default-src 'none'` CSP and contains no script. Colors are schema-validated (hex/rgb only), font names filtered, all text escaped, so project content cannot inject markup or CSS.
- No user-supplied code is executed. `apply_operations` accepts only schema-validated structured operations.
- stdout carries only MCP messages; logs go to stderr without image data or environment values.
- Configurable limits: canvas side/pixels, asset bytes/pixels, layers per page, operations per batch, assets per import, pages per export, render timeout.
- Existing output files are never overwritten unless `overwrite: true`; exports go to new timestamped folders by default.
## Fonts
`fontFamily` is a CSS family list. Use installed fonts, or import font files with `purpose: "font"` and `fontFamily: "Brand Sans"`. Text is measured after `document.fonts.ready`. The renderer asks Chromium (via CDP) which **platform fonts actually drew each text layer** and reports:
- `FONT_MISSING`: none of the requested fonts available.
- `FONT_FALLBACK`: primary font not used.
- `FONT_PARTIAL_FALLBACK`: e.g. Latin font plus a CJK fallback for Chinese glyphs.
`shotluma-design-mcp doctor` lists which common families exist on the machine. For reproducible output across machines, import the font files into the project.
## CLI
```bash
shotluma-design-mcp [serve] [--allow DIR]... [--browser EXE] [--no-image-return] # MCP server (default)
shotluma-design-mcp doctor # environment, browser, render and font check
shotluma-design-mcp install-browser # download the matching Chromium
shotluma-design-mcp validate <project>
shotluma-design-mcp render <project> [--page ID]
shotluma-design-mcp export <project> [--out DIR] [--zip] [--project-copy] [--overwrite]
```
The engine is also a library (`import { DesignService } from 'shotluma-design-mcp'`), independent of MCP.
## Configuration
| Variable / flag | Default | Meaning |
|---|---|---|
| `--allow DIR` / `SHOTLUMA_ALLOWED_DIRS` (path-delimited) | working directory | readable/writable roots |
| `--browser EXE` / `SHOTLUMA_BROWSER_PATH` | auto-detect | Chromium/Chrome/Edge executable |
| `--no-image-return` / `SHOTLUMA_DISABLE_IMAGE_RETURN=1` | off | never return image content |
| `SHOTLUMA_LOG_LEVEL` | `info` | `debug`/`info`/`warn`/`error` (stderr) |
| `SHOTLUMA_MAX_CANVAS_SIDE` / `_CANVAS_PIXELS` | 8192 / 40 000 000 | canvas limits |
| `SHOTLUMA_MAX_ASSET_BYTES` / `_ASSET_PIXELS` | 50 MB / 100 MP | asset limits |
| `SHOTLUMA_MAX_LAYERS_PER_PAGE` / `_OPERATIONS` / `_ASSETS_PER_IMPORT` / `_PAGES_PER_EXPORT` | 500 / 500 / 100 / 50 | batch limits |
| `SHOTLUMA_PREVIEW_MAX_SIDE` | 1024 | size of returned preview images |
| `SHOTLUMA_RENDER_TIMEOUT_MS` | 60000 | per render |
## Troubleshooting
| Symptom | Fix |
|---|---|
| `BROWSER_NOT_FOUND` | `npx playwright-core install chromium` (or `shotluma-design-mcp install-browser`), or set `SHOTLUMA_BROWSER_PATH` to Chrome/Edge. Linux may also need `npx playwright-core install-deps chromium`. |
| `PATH_NOT_ALLOWED` | Add the folder with `--allow` in the client config and restart the server. |
| `PROTECTION_VIOLATION` | The batch would stretch/crop/rotate/fade a protected asset. Keep it upright and uniform, or record the user's grant. |
| `PROTECTED_OCCLUDED` / `PROTECTED_PIXELS_ALTERED` | Something (often a neighbour's shadow) covers a screenshot. The message names the likely layer. Add space or reduce the shadow. |
| `PROTECTED_CROPPED_BY_CANVAS` | Move/scale the device fully inside the canvas. |
| `FONT_MISSING` / CJK shows tofu or a different face | Install or import a font with those glyphs; add it to `fontFamily`. |
| `OUTPUT_EXISTS` | Choose another `outputDir`, or pass `overwrite: true` only if the user asked. |
| `ASSET_MODIFIED` | An asset file in `assets/` was changed after import; re-import the original. |
| Client shows no tools | Check the absolute path to `dist/cli.js`, run `node dist/cli.js doctor`, and read the client's MCP log (server logs are on stderr). |
## Development
```bash
npm run typecheck # tsc --noEmit
npm test # all suites (unit, rendering, integration — build first)
npm run test:unit
npm run test:rendering # needs a browser
npm run test:integration # builds, then drives dist/cli.js over stdio with the official SDK client
npm run fixtures # regenerate neutral test screenshots
npm run showcase # rebuild examples/showcase via MCP
npm pack # tarball for local install tests
```
Layout: `src/engine` (schema, geometry, operations, protection), `src/assets`, `src/project`, `src/layout`, `src/renderer`, `src/validation`, `src/guidelines`, `src/service` (transport-independent API), `src/mcp`, `src/cli.ts`.
### Publishing
Not published. When ready:
```bash
npm run typecheck && npm test && npm pack --dry-run
npm login
npm publish --access public
```
## Known limitations
- Verified on Windows 11 x64 / Node 24 / Chromium 1234 only. macOS and Linux are expected to work (browser discovery covers them) but were not tested. Linux containers usually need `playwright-core install-deps`.
- Text rendering depends on installed fonts; output can differ across machines unless fonts are imported into the project.
- Text measurement is box-based: a very tight `lineHeight` (< 1) lets glyph descenders exceed the measured line box, so a collision can go unreported. Review the preview.
- Perspective uses CSS `rotateX/rotateY`, not arbitrary four-corner mapping.
- Validation of overlap between unrelated decorations uses bounding boxes (deliberately lenient).
- No GUI editor, PSD/Figma import, or remote rendering — by design.
## License
MIT. See [LICENSE](LICENSE), [NOTICE](NOTICE) (upstream attribution) and [ASSET_LICENSES.md](ASSET_LICENSES.md). All bundled test and example images are self-generated by this project.
TDQS
Scored across 10 tools
The mutation/creation tools (create_project, open_project, import_assets, export_design, apply_operations) and the generation tools (list_layout_styles, generate_layout) have clearly distinct roles. The main soft spot is the read-side trio inspect_design, render_preview and validate_design, which all report measurements and validation issues, so an agent must read descriptions carefully to pick the right one. The descriptions do clarify the split (structure read vs raster output vs gating), so it is manageable but not perfectly crisp.
Every tool follows the same verb_noun snake_case pattern: list_layout_styles, generate_layout, apply_operations, inspect_design, render_preview, validate_design, create_project, open_project, import_assets, export_design. No camelCase or naming-style deviations anywhere in the surface.
Ten tools is well within the sweet spot for a design-authoring server. Deliberately funneling all mutations through a single atomic apply_operations keeps the surface small while the remaining tools each own a distinct lifecycle stage (create/open/import/layout/edit/inspect/validate/preview/export). No tool looks redundant.
Coverage is strong end to end: project creation and opening, asset import, generation of layouts, full layered mutation via apply_operations (including page/layer add, update, remove, reorder, grouping, brand, asset protection), inspection, validation, preview and export. Minor gaps remain: there is no way to list or delete existing projects, and no targeted single-layer query, so an agent must call the broader inspect_design to read a small piece of the design.