MCP Integration

Draftila implements a Model Context Protocol (MCP) server, allowing AI agents like Claude to design directly in your Draftila editor.

How It Works

  1. The AI agent sends tool calls to the Draftila API via MCP
  2. The API proxies these operations to the browser editor via WebSocket
  3. The browser executes the operations on the canvas (for accurate text measurement, layout, and rendering)
  4. Results are streamed back to the AI agent

All operations happen in real-time — you can watch the AI design in your editor as it works.

Setup

Prerequisites

  • A running Draftila instance
  • An API key (see API Keys)
  • An MCP-compatible client (e.g., Claude Desktop, Claude Code)

Configuration

Add Draftila as an MCP server in your client's configuration. For Claude Desktop, add to your claude_desktop_config.json:
JSON
{
  "mcpServers": {
    "draftila": {
      "url": "https://your-draftila-instance.com/mcp",
      "headers": {
        "Authorization": "Bearer <your-api-key>"
      }
    }
  }
}

Replace the URL with your actual Draftila instance URL and use a real API key.

Opening a Draft

You must have a draft open in the Draftila editor in your browser for MCP operations to work. The AI agent operates on whichever draft is currently active.

Available Tools

The MCP server exposes 30+ tools organized into categories.

Draft Management

ToolDescription
list_draftsList all accessible drafts
list_pagesList pages in the current draft
add_pageCreate a new page
remove_pageDelete a page
rename_pageRename a page
set_active_pageSwitch the active page

Shape Creation

ToolDescription
create_shapeCreate a single shape (recommended for live feedback)
batch_create_shapesCreate multiple shapes at once (max 50)
get_shapeGet a shape's properties
update_shapeModify shape properties
batch_update_shapesUpdate multiple shapes at once
delete_shapesDelete shapes
list_shapesList all shapes or children of a shape
duplicate_shapesDuplicate shapes

Grouping and Layout

ToolDescription
group_shapesGroup shapes together
ungroup_shapesUngroup a group
frame_selectionWrap shapes in a frame
apply_auto_layoutApply auto-layout to a frame
align_shapesAlign shapes (left, center, right, top, middle, bottom)
distribute_shapesDistribute shapes evenly (3+ shapes)
nudge_shapesMove shapes by an offset
flip_shapesFlip horizontally or vertically
move_in_stackChange z-order (forward, backward, to front, to back)
move_by_dropReparent a shape into another container

Vector and Boolean

ToolDescription
boolean_operationUnion, subtract, intersect, or exclude shapes

Components

ToolDescription
create_componentDefine a reusable component
create_instanceCreate a component instance
list_componentsList all components
remove_componentDelete a component

Export, Import, and Code Generation

ToolDescription
export_svgExport as SVG markup
export_pngExport as base64 PNG (configurable scale and background)
export_cssExport as CSS code (dimensions, fills, borders, flexbox)
export_css_all_layersExport as CSS with rules for all descendant layers
export_swiftuiExport as SwiftUI code (HStack/VStack, modifiers)
export_composeExport as Jetpack Compose code (Row/Column, Modifiers)
import_svgParse SVG and create shapes
list_iconsList available Lucide icons
insert_iconInsert a Lucide icon as SVG

Guides and Variables

ToolDescription
list_guidesList ruler guides
add_guideAdd a guide line
remove_guideRemove a guide
list_variablesList color tokens
set_variableCreate or update a color token
delete_variableDelete a color token

Limitations

  • Each MCP operation has a 30-second timeout
  • The draft must be open in a browser tab for operations to execute
  • Batch operations are limited to 50 shapes per call
  • The AI sees the same design state as your editor — changes are synced in real-time