Skip to main content
Glama
README.md
<div align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/images/banner-dark.png" />
    <source media="(prefers-color-scheme: light)" srcset="docs/images/banner-light.png" />
    <img src="docs/images/banner-dark.png" alt="Carton — open-source local design editor and Paper MCP alternative" width="760" />
  </picture>

  <p>
    <strong>An open-source, Fully and completely Vibe coded local alternative to Paper and Paper MCP.</strong><br />
    Currently Linux design editor and MCP server where you and coding agents edit the same canvas.
  </p>

  <p>
    <a href="https://github.com/fbal98/carton/actions/workflows/ci.yml"><img src="https://github.com/fbal98/carton/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
    <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0B0B0B.svg" alt="License: MIT" /></a>
    <a href="#quick-start"><img src="https://img.shields.io/badge/platform-Linux-5E594F.svg" alt="Platform: Linux" /></a>
    <a href="#quick-start"><img src="https://img.shields.io/badge/node-%3E%3D22.13-339933.svg" alt="Node.js >= 22.13" /></a>
    <a href="#paper-and-paper-mcp-compatibility"><img src="https://img.shields.io/badge/MCP-47%20tools-C2854C.svg" alt="MCP: 47 tools" /></a>
    <a href="https://github.com/fbal98/carton/issues"><img src="https://img.shields.io/github/issues/fbal98/carton?color=C2854C" alt="GitHub issues" /></a>
    <a href="https://github.com/fbal98/carton/stargazers"><img src="https://img.shields.io/github/stars/fbal98/carton?style=flat" alt="GitHub stars" /></a>
  </p>

  <p>
    <a href="#quick-start">Quick start</a> ·
    <a href="#connect-an-mcp-client">Connect MCP</a> ·
    <a href="#try-the-included-example">Example</a> ·
    <a href="#workflows">Workflows</a> ·
    <a href="CONTRIBUTING.md">Contributing</a>
  </p>
</div>

![Carton editor showing desktop and mobile billing artboards with the Layers tree and Design inspector](docs/images/carton-editor.png)

Carton is a local Linux design tool built around real HTML, CSS, and SVG layers. You can open it as a desktop app to arrange artboards, edit styles, manage CSS tokens, and pin comments, while agents like Claude Code or Codex read and write the exact same workspace over MCP.

Everything lives in a local SQLite database on your machine. You do not need a cloud account or a hosted backend, and `carton mcp` still works headlessly when the editor window is closed.

## Paper and Paper MCP compatibility

Carton implements the 41 tool names and input schemas from Paper MCP (`src/catalog.json`), so existing prompts, skills, and agent workflows written for Paper work locally out of the box. On top of that base surface, Carton adds 6 tools for workflows that usually take too many round trips:

| Capability | Details |
| --- | --- |
| Compatible MCP tools (41) | Files, folders, pages, artboards, HTML/CSS writing, style updates, text edits, tokens, comments, JSX export, screenshots, PNG/PDF export |
| Batch manifests (`sync_boards`) | Build and update multiple boards from HTML templates, shared CSS, data, and locale/state/viewport matrices, with Chromium layout linting and cached exports |
| Live web import (`import_url`) | Capture a running local or remote route across multiple viewports and interactive states into editable layers |
| Component import (`import_component`) | Render local React/Vite, Storybook, or Next.js components directly into editable artboards |
| Active tab capture (`capture_element`) | Pull an open page or selector from an agent-controlled Chromium DevTools port, CLI, or Playwright script |
| Vector & asset helpers | Update individual SVG attributes by node ID (`update_vector_attributes`) and insert local images without sending image bytes through the model (`insert_image`) |

## Quick start

### Requirements

Carton targets Linux and needs:

- Node.js 22.13 or newer and npm
- System Chromium or Google Chrome (used for rendering, linting, and imports)
- Fontconfig and FFmpeg
- Poppler (`pdftotext`) if you run the PDF export tests
- Optional: system Electron (falls back to a dedicated Chromium `--app` window if Electron is absent)

### Install and run from source

```sh
git clone https://github.com/fbal98/carton.git
cd carton
npm ci
npm test
npm start
```

Install the user-local `carton` CLI shim (`~/.local/bin/carton`) and Linux `.desktop` entry:

```sh
npm run install:desktop
```

Run `npm run install:desktop` again if you move the checkout. You can override executable paths with `CARTON_ELECTRON` or `CARTON_CHROMIUM` when needed.

If you prefer running Carton in a regular browser tab or exposing its Streamable HTTP MCP endpoint over loopback:

```sh
node bin/carton.js serve
```

This prints the local editor URL (with the session bearer token in the URL fragment) and the `/mcp` HTTP endpoint. Set `CARTON_PORT` to pin a fixed port.

## Connect an MCP client

Open Carton and click **Connect MCP** in the top bar to copy a ready-to-paste stdio configuration. With `~/.local/bin` on your `PATH`, any MCP client can connect using:

```json
{
  "mcpServers": {
    "carton": {
      "command": "carton",
      "args": ["mcp"]
    }
  }
}
```

For Claude Code or Codex CLI:

```sh
# Claude Code
claude mcp add carton -- carton mcp

# Codex CLI
codex mcp add carton -- carton mcp
```

This repository also includes a checked-in `.codex/config.toml` that connects `carton mcp` and enables the main design, import, sync, and vector tools.

When the editor is open, `carton mcp` relays calls to it so changes appear live on the canvas. When no editor is running, `carton mcp` operates directly on the SQLite workspace database, and the editor picks up the changes the next time it opens. Set `CARTON_HEADLESS=0` if you want calls to require a running editor window.

## Try the included example

The repo ships a synthetic two-board example under [`examples/pricing/`](examples/pricing/boards.json) (`styles.css`, `billing.html`, and `mobile-card.html`).

Once your MCP client is connected, ask your agent:

> Call `get_basic_info`, then run `sync_boards` on `/absolute/path/to/carton/examples/pricing/boards.json` and open the result in Carton.

Carton will resolve the shared stylesheet and CSS custom properties, create the **Billing · Desktop** and **Billing · Mobile** artboards, run Chromium layout and contrast checks on both viewports, and export PNGs plus a combined PDF.

## Workflows

### Design a UI with an agent

Start a session with an agent connected to Carton and ask for a screen, for example: "Create a settings screen on the current canvas, draw an editable SVG icon for each section, and show me the result."

- `create_artboard` accepts `html` directly so a screen can be built in one call, or `htmlPath` for larger markup on disk.
- `write_html` and `create_artboard` accept `<style>` blocks, `class` attributes, and shared stylesheets (`css` or `cssPath`). Carton resolves specificity, `!important`, and `@media` at the board's width and stores inline styles so the canvas, exports, and `get_jsx` match. `:root` custom properties are copied where used. Pseudo-classes such as `:hover`, pseudo-elements, and `@keyframes` are reported in `warnings`. `dir` and `lang` attributes are preserved on layers and in `get_jsx`.
- Local images work via `src="file:///abs/path.png"` or `insert_image`, keeping raw image bytes out of the model context.
- `update_vector_attributes` edits SVG shapes in place without replacing their layer ID (for example `{"stroke":"#237960","d":"M2 12L8 18L22 3"}`).
- `get_screenshot` caps inline images near 1.15 megapixels for vision models. Pass `output: "file"` for full-scale PNGs or `region` to crop a specific area.
- Call `finish_working_on_nodes` when done to clear the editing indicator on the canvas.

### Sync boards from a manifest

`sync_boards` builds or updates an entire page from a JSON manifest listing shared stylesheets, HTML templates, and board definitions. Templates support `{{data}}`, `{{#lists}}`, and `{{> partials}}`. Board variants can expand over locales, states, and viewports, such as `"expand": {"locale": ["en", "ar"], "state": ["full", "empty"]}`, and Arabic or other RTL locales automatically set `dir="rtl"`.

```json
{
  "css": ["styles.css"],
  "boards": [
    { "name": "Welcome", "width": 390, "height": 844, "template": "screen.html" }
  ]
}
```

- Only boards whose source changed are rewritten. Unchanged chains of `layer-name` attributes keep their layer IDs so comment threads stay pinned (a thread on a removed layer moves to the nearest kept ancestor).
- Boards edited manually on the canvas since their last sync are reported as `conflict` and skipped unless `onConflict` is `overwrite` or `fork`. One undo reverts a full sync.
- Changed boards are linted in Chromium at their own viewport for clipped or overflowing text, layers extending past the board edge, overlapping text, WCAG contrast, and RTL issues. Full findings go to `lint.json`, and inline crops cover only flagged regions.
- Exports write one PNG per board (3x up to 600px wide, otherwise 2x) and one combined PDF, cached by board content.

### Import a component from source

Call `import_component` with an absolute `componentPath`, or with `projectDir` plus a relative path. The source project must live on the same machine with its dependencies installed.

```json
{
  "projectDir": "/work/shop",
  "componentPath": "src/components/PricingCard.tsx",
  "props": { "plan": "Pro" },
  "viewports": [{ "width": 1440, "height": 900 }, { "width": 390, "height": 844 }]
}
```

- React and Vite: uses the project's Vite config and CSS imports. Pass `exportName`, `wrapperPath` (a default-exported provider), or `styles` for isolated mounts.
- Storybook: loads a matching story from a local `storybook-static` build or a sibling `.stories` module, with `story` selecting a variant.
- Next.js: derives App Router or Pages Router routes from filenames and serves them in a temporary copy. Pass `route` for dynamic paths (such as `/products/42`) and a CSS `selector` to isolate one component inside a page layout.

### Import a running web app

Call `import_url` with any URL to capture a 1440x900 viewport into the active page, or pass `selector`, `readySelector`, `viewports`, and multi-state `states` with browser `steps` (`click`, `fill`, `press`, `select`, `check`, `hover`, `waitFor`, `wait`, `goto`, `scroll`, `evaluate`). You can also pass Playwright `storageState`, `cookies`, `headers`, `locale`, `timezoneId`, and `colorScheme`.

```json
{
  "url": "http://localhost:3000/menu",
  "name": "Menu",
  "storageState": "/work/shop/.auth/guest.json",
  "viewports": [{ "width": 390, "height": 844 }],
  "states": [
    { "name": "Browsing" },
    {
      "name": "Cart open",
      "steps": [
        { "action": "click", "selector": "text=Add to cart" },
        { "action": "click", "selector": "role=button[name=\"Cart\"]" }
      ]
    }
  ]
}
```

You can also trigger this from the desktop UI via **Import URL**. Carton embeds available images and web fonts, converts form values to static layers, falls back to image layers for `<canvas>`, `<video>`, `<iframe>`, or unsupported SVG features, and reports the sampled pixel difference between the source page and the imported artboard. One undo removes the entire import.

### Capture from an open browser or Playwright

When an agent already controls Chromium on a DevTools port, call `capture_element` with `debugPort`, a CSS `selector`, and optional `targetId` or `targetUrl`. Carton leaves the tab open in its current state.

From the terminal:

```sh
carton capture --cdp 9222 --url /checkout --selector main
```

From a Playwright script or test:

```js
import { captureToCarton } from "/path/to/carton/src/capture.js";

await page.getByRole("button", { name: "Checkout" }).click();
await captureToCarton(page, { fileId, pageId, name: "Checkout · Mobile", selector: "main" });
```

### Use the desktop editor

Open **Carton** from your applications menu or run `carton app`.

- Drag layers on the canvas to move them, and drag the bottom-right handle to resize.
- Shortcuts: `V` select, `H` pan, `A` artboard, `R` rectangle, `T` text, `P` pen path (`Enter` finishes a path), `1` fit page.
- Scroll to pan and hold `Ctrl` while scrolling to zoom around the cursor.
- Drag rows in Layers to reorder, or hold `Shift` on drop to nest a layer.
- Double-click a page name to rename or reorder it. Use the workspace menu to create, move, rename, archive, and restore files and folders.
- The Design inspector includes three procedural shader effects powered by [`@paper-design/shaders`](https://github.com/paper-design/shaders) (`@paper-design/shaders-react` in JSX output).

## Storage and security

- Workspaces are stored in `$XDG_DATA_HOME/carton/workspace.sqlite` (default `~/.local/share/carton/workspace.sqlite`), with exports written to the adjacent `exports/` folder. Set `CARTON_HOME` on both the editor and CLI to isolate a separate workspace.
- SQLite transactions serialize concurrent edits between the editor and MCP clients. Carton keeps 50 diff-based undo steps across restarts and deduplicates stored images and fonts by SHA-256 (`carton-asset:<sha256>`).
- Connect only MCP clients you trust, and use `import_component` only on trusted local projects because it runs project code. Review imported URLs and exports before sharing them. See [`SECURITY.md`](SECURITY.md) for reporting vulnerabilities and redaction details.

## Contributing

Bug reports, Linux packaging fixes, editor improvements, and MCP tests are all welcome. Read [`CONTRIBUTING.md`](CONTRIBUTING.md) for setup instructions, project layout, and pull request guidelines. Participation is governed by the [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).

## License

Carton is released under the [MIT License](LICENSE).