Skip to content

MCP Overview

Caja implements a Model Context Protocol server, allowing AI agents to interact with the design canvas programmatically.

How It Works

  1. An MCP client (Claude Code, Cursor, etc.) connects to Caja via stdio
  2. The agent discovers available tools and resources
  3. The agent calls tools to build and modify layouts
  4. Changes appear in real-time on the canvas

Available Tools

Caja provides 31 tools across six categories:

Frame Manipulation

ToolDescription
add_frameAdd a new element (box, text, image, button, input, textarea, select, link)
update_frameUpdate properties of an existing frame
update_spacingUpdate padding, margin, or inset
update_sizeUpdate width or height (default, hug, fill, fixed)
remove_frameDelete a frame from the tree
move_frameMove a frame to a new parent at a given index
wrap_frameWrap a frame in a new parent box
duplicate_frameDeep clone a frame with new IDs
rename_frameRename a frame
select_frameSelect a frame in the UI

Tree Operations

ToolDescription
get_treeRead the full frame tree (use summary: true for compact LLM-friendly output)
get_selectedGet the currently selected frame with all properties
batch_updateExecute multiple operations in a single undo step with $prev/$N variable substitution

Responsive

ToolDescription
set_breakpointActivate a responsive breakpoint (base, xl, md)
get_breakpointGet current active breakpoint and canvas width
get_responsive_overridesGet responsive overrides for a frame
clear_responsive_overridesClear overrides at a breakpoint

Components

ToolDescription
list_componentsList available reusable components (filterable by tag)
insert_componentInsert a component instance with child overrides
save_componentSave a frame as a reusable component
delete_componentDelete a component
edit_componentEnter component edit mode (isolated master editing)
exit_component_editExit edit mode, propagate changes to all instances
export_libraryExport components as a .cjl file

Media

ToolDescription
screenshotTake a PNG screenshot of the canvas
upload_assetDownload an external image to local storage

Pages & Files

ToolDescription
new_fileReset to blank state
list_pagesList all pages
switch_pageSwitch to a different page
add_pageAdd a new page
remove_pageRemove a page

See the Tools Reference for detailed schemas and examples.

Tailwind Classes Shortcut

Most tools accept a classes parameter — a Tailwind class string that gets parsed into frame properties:

"classes": "flex gap-4 p-8 bg-blue-500 rounded-lg"

This is the fastest way to style elements. The parser recognizes layout, spacing, sizing, colors, typography, borders, effects, transforms, and more. Unrecognized classes are passed through as custom Tailwind classes.

Auto Token Matching

Raw numeric and color values are automatically matched to Tailwind tokens:

  • gap: 16gap-4 (spacing token)
  • bg: "#ef4444"bg-red-500 (color token)
  • fontSize: 14text-sm (font size token)

This means agents can send raw values and get clean Tailwind output.

Responsive Workflow

The MCP responsive workflow follows a large-first approach:

  1. Build the base layout at the base (LG) breakpoint
  2. Call set_breakpoint({ breakpoint: "xl" }) to switch to MD (Medium)
  3. Use update_frame, update_spacing, or update_size — changes are saved as sparse overrides
  4. Call set_breakpoint({ breakpoint: "md" }) for SM (Small) adjustments
  5. Call set_breakpoint({ breakpoint: "base" }) to return to LG

Only properties that differ from the base are stored. The exported code uses max-xl: and max-md: prefixed Tailwind classes.

Resources

Agents can also read state via MCP resources:

URIDescription
caja://treeFull frame tree JSON
caja://selectedCurrently selected frame
caja://exportExported Tailwind classes
caja://export/htmlFull HTML export
caja://componentsComponent catalog