API Reference

Layout CLI exposes 14 MCP tools that AI agents call automatically during development. These tools give your agent structured access to design tokens, component specs, compliance checking, live preview, and a two-way Figma bridge: everything needed to build UI that stays on brand.

All tools are available after running npx @layoutdesign/context init and adding the MCP server config to your agent's settings. See the CLI guide for setup instructions.

The Full Code-to-Design Loop

The MCP tools are designed to work together across the full development workflow, from the first prompt to a Figma-reviewed, production-ready component. No other open-source tool closes this loop.

plaintext
Developer prompts Claude Code / Cursor
  │
  ▼
Claude calls get_design_system
  │  (loads colour, typography, spacing, component specs)
  ▼
Claude generates on-brand TSX
  │
  ▼
Claude calls preview
  │  (renders live at localhost:4321)
  ▼
Developer reviews in browser, requests tweaks
  │
  ▼
Claude calls push_to_figma
  │  (sends editable frames to Figma via Figma MCP)
  ▼
Designer reviews and tweaks in Figma
  │
  ▼
Developer asks Claude to read Figma changes
  │  (via Figma MCP read tools)
  ▼
Claude updates TSX to match designer's changes
  │
  ▼
Commit. Design and code are in sync.
The loop works best when Claude calls get_design_system automatically at the start of every UI task. Add a rule to your CLAUDE.md or .cursorrules instructing the agent to fetch design context before writing any UI code. The exported bundle from Layout Studio includes this instruction pre-written.

Tools

get_design_system

Returns the full layout.md file, or a specific named section of it. Use this as the first call when starting any UI task. It gives the agent the complete design context it needs to produce on-brand code.

Parameters

NameTypeDescription
sectionstring (optional)Named section to return. One of: "quick-reference", "colour", "typography", "spacing", "components", "elevation", "motion", "anti-patterns". Omit to return the full file.

Example

typescript
// Agent calls this at the start of a UI task
const designSystem = await mcp.call("get_design_system");

// Or fetch a specific section to reduce token usage
const colourSystem = await mcp.call("get_design_system", {
  section: "colour"
});

get_tokens

Returns design tokens in a specific format and optionally filtered by token type. Use this when you need raw token values for a stylesheet, Tailwind config, or JSON exchange.

Parameters

NameTypeDescription
format"css" | "json" | "tailwind"Output format. css returns CSS custom properties, json returns W3C DTCG format, tailwind returns a theme extension object.
type"colour" | "typography" | "spacing" | "radius" | "effect" (optional)Filter tokens by type. Omit to return all token types.

Example

typescript
// Get all CSS tokens
const tokens = await mcp.call("get_tokens", { format: "css" });

// Get only colour tokens as JSON
const colours = await mcp.call("get_tokens", {
  format: "json",
  type: "colour"
});

// Get Tailwind theme extension
const tailwindTheme = await mcp.call("get_tokens", {
  format: "tailwind"
});

get_component

Returns the full specification for a named component, including its anatomy, token mappings for all states, and a working TSX code example. Use this before building or modifying any component that exists in the design system.

Parameters

NameTypeDescription
namestringComponent name, case-insensitive. Examples: "Button", "Card", "Input", "Modal". Use list_components to discover available names.

Example

typescript
// Get the Button component spec before building it
const buttonSpec = await mcp.call("get_component", {
  name: "Button"
});

// Returns: anatomy, token mappings for default/hover/focus/active/disabled/loading/error,
// and a full TSX example using the design system tokens

list_components

Returns an inventory of all components available in the design system, with name, description, variant count, and property definitions for each. Use this to discover what components exist before calling get_component.

No parameters. Call with no arguments.

Example

typescript
// Discover all available components
const components = await mcp.call("list_components");

// Returns an array like:
// [
//   { name: "Button", description: "Primary action element", variants: 4 },
//   { name: "Card", description: "Content container", variants: 2 },
//   ...
// ]

check_compliance

Validates a code snippet against the design system rules defined in the Anti-Patterns section of layout.md. Returns a compliance score, a list of violations with line references, and suggested fixes. Run this before submitting any UI code. Runs 12 rules covering colours, spacing, typography, accessibility, and motion.

Parameters

NameTypeDescription
codestringThe TSX or CSS code snippet to validate.
rulesstring[] (optional)Specific rule IDs to check against. Omit to run all rules. Available rules: no-hardcoded-colours, use-design-tokens, no-hardcoded-spacing, no-unknown-components, spacing-compliance, font-family-compliance, border-radius-compliance, interactive-state-coverage, accessibility-alt-text, accessibility-button-label, semantic-html, motion-token-compliance.

Example

typescript
const result = await mcp.call("check_compliance", {
  code: `
    <div style={{ color: "#6366f1" }}>
      <button className="bg-blue-500 text-white px-4 py-2">
        Submit
      </button>
    </div>
  `
});

// Returns:
// {
//   score: 42,
//   violations: [
//     { rule: "no-hardcoded-colours", line: 2, fix: "Use var(--color-primary) instead of #6366f1" },
//     { rule: "use-design-tokens", line: 3, fix: "Replace bg-blue-500 with bg-[var(--color-primary)]" }
//   ]
// }

preview

Renders a TSX component snippet live in a local browser canvas at localhost:4321. The component is transpiled server-side and displayed in a sandboxed iframe with React and Tailwind loaded. Use this to visually confirm a component looks correct before committing the code.

Parameters

NameTypeDescription
codestringThe TSX component code to render. Must be a valid React component.
propsRecord<string, unknown> (optional)Props to pass to the rendered component.

Example

typescript
// Render a component for visual review
await mcp.call("preview", {
  code: `
    export default function PricingCard({ plan, price }: { plan: string; price: string }) {
      return (
        <div className="rounded-xl border border-gray-200 p-6 bg-white">
          <h3 className="text-lg font-semibold text-[#0a0a0a]">{plan}</h3>
          <p className="text-3xl font-bold text-gray-900 mt-2">{price}</p>
        </div>
      );
    }
  `,
  props: { plan: "Pro", price: "£19/mo" }
});
// Opens/refreshes localhost:4321 with the rendered component

push_to_figma

Sends a rendered component to Figma as a set of editable frames via the Figma MCP plugin. Supports two modes: capture (default) renders the component and pushes screenshot-based frames, native creates editable Figma objects with auto-layout using the Figma MCP directly (no Playwright required). Requires the Figma MCP plugin to be installed.

Parameters

NameTypeDescription
codestringThe TSX component code to render and push.
mode"capture" | "native" (optional)Push mode. "capture" (default) renders the component and pushes screenshot-based frames. "native" creates editable Figma objects with auto-layout via the Figma MCP. Native mode does not require Playwright MCP.
pageNamestring (optional)Figma page to push the frame to. Defaults to "AI Components".
frameNamestring (optional)Name for the created frame. Defaults to the component function name.

Example

typescript
// Push a generated component to Figma for designer review (capture mode)
await mcp.call("push_to_figma", {
  code: `
    export default function HeroBanner() {
      return (
        <section className="bg-[var(--color-bg-surface)] px-8 py-16">
          <h1 className="text-5xl font-black text-[var(--text-primary)]">
            Your AI builds on-brand.
          </h1>
        </section>
      );
    }
  `,
  pageName: "Sprint 3 -  Components",
  frameName: "HeroBanner / Desktop"
});

// Push as editable Figma objects (native mode, no Playwright needed)
await mcp.call("push_to_figma", {
  code: `
    export default function HeroBanner() {
      return (
        <section className="bg-[var(--color-bg-surface)] px-8 py-16">
          <h1 className="text-5xl font-black text-[var(--text-primary)]">
            Your AI builds on-brand.
          </h1>
        </section>
      );
    }
  `,
  mode: "native",
  pageName: "Sprint 3 -  Components"
});

push_tokens_to_figma

Pushes design system tokens from the loaded kit to Figma as native variables and styles. Creates colour variables, text styles, and effect styles that designers can use directly in their Figma file. Requires the Figma MCP plugin to be installed.

Parameters

NameTypeDescription
fileKeystring (optional)Figma file key to push tokens into. If omitted, creates a new file.

Example

typescript
// Push tokens to an existing Figma file
await mcp.call("push_tokens_to_figma", {
  fileKey: "EHmQZ1wq5qHUcifyRYtiBC"
});

// Push tokens to a new Figma file
await mcp.call("push_tokens_to_figma");

url_to_figma

Captures a public URL (a live webpage or web app) into Figma as a set of editable frames. Each capture includes both a full-page screenshot and a viewport-cropped version. Useful for documenting reference designs or snapshotting production UI alongside component work.

Parameters

NameTypeDescription
urlstringThe public URL to capture.
pageNamestring (optional)Figma page to push the frames to. Defaults to "URL Captures".
viewportsArray<{ width: number; height: number }> (optional)Viewport dimensions to capture. Defaults to desktop (1440×900) and mobile (390×844).

Example

typescript
// Capture a reference site into Figma
await mcp.call("url_to_figma", {
  url: "https://linear.app",
  pageName: "Reference -  Linear",
  viewports: [
    { width: 1440, height: 900 },
    { width: 390, height: 844 }
  ]
});
// Creates annotated frames in Figma with the captured screenshots

design_in_figma

Designs UI directly in Figma using your extracted design tokens. Takes a natural language prompt describing what to design, extracts the relevant colour, typography, and spacing tokens from your loaded kit, and returns structured instructions for the Figma MCP generate_figma_design tool.

Parameters

NameTypeDescription
promptstring (required)Natural language description of what to design, e.g. 'A settings page with sidebar navigation'.
fileKeystring (optional)Figma file key to design into. If omitted, instructions are returned without a target file.
viewportsArray<{ width: number; height: number }> (optional)Viewport dimensions for the design. Defaults to desktop (1440×900).

Example

typescript
// Design a dashboard directly in Figma using your tokens
await mcp.call("design_in_figma", {
  prompt: "A settings page with sidebar navigation and dark theme",
  fileKey: "EHmQZ1wq5qHUcifyRYtiBC"
});
// Returns token palette + Figma MCP instructions

update_tokens

Updates or adds design tokens in the currently loaded kit. Accepts new token values and merges them into the existing token set, persisting changes to the kit files.

Parameters

NameTypeDescription
tokensRecord<string, string> (required)Object of token name-value pairs to add or update, e.g. { '--color-primary': '#6366F1' }.
format'css' | 'json' | 'tailwind' (optional)Which token file to update. Defaults to 'css' (tokens.css).

Example

typescript
// Add a new brand colour token
await mcp.call("update_tokens", {
  tokens: { "--color-brand": "#6366F1", "--color-brand-hover": "#7577F3" },
  format: "css"
});

get_screenshots

Returns design system reference screenshots captured during website extraction. Returns full-page and/or viewport screenshots as images that can be used for visual comparison when building UI components.

Parameters

NameTypeDescription
type"full-page" | "viewport" | "all" (optional)Which screenshot to return. Defaults to "all" which returns both full-page and viewport captures.

Example

typescript
// Get all reference screenshots
const screenshots = await mcp.call("get_screenshots");

// Get only the viewport-cropped screenshot
const viewport = await mcp.call("get_screenshots", {
  type: "viewport"
});

scan_project

Scans the project directory for React components and Storybook stories. Returns component names, file paths, props, import paths, and story associations. Auto-runs on MCP server startup so AI agents see your existing codebase components via list_components and reuse them instead of generating duplicates.

Parameters

NameTypeDescription
pathstring (optional)Directory to scan. Defaults to the current working directory.
type"storybook" | "codebase" | "both" (optional)What to scan for. "storybook" finds CSF3 story files, "codebase" finds React component exports, "both" (default) scans for all.

Example

typescript
// Scan the current directory for all components and stories
const result = await mcp.call("scan_project");

// Scan a specific path for Storybook stories only
const stories = await mcp.call("scan_project", {
  path: "./src",
  type: "storybook"
});

// Returns:
// {
//   components: [
//     { name: "Button", path: "src/components/Button.tsx", importPath: "@/components/Button", props: [...] },
//     ...
//   ],
//   stories: [
//     { name: "ButtonStory", component: "Button", path: "src/stories/Button.stories.tsx" },
//     ...
//   ]
// }

check_setup

Diagnoses and optionally fixes MCP server setup issues. Call this when Figma tools (push_to_figma, design_in_figma, url_to_figma) are not working. Checks MCP registration, transport type, OAuth status, and endpoint reachability. With fix enabled, attempts to re-register missing or misconfigured servers.

Parameters

NameTypeDescription
focus"all" | "figma" | "playwright" | "layout" (optional)What to check. Defaults to "all".
fixboolean (optional)If true, attempts to auto-fix issues by re-registering MCP servers. Defaults to false (report only).

Example

typescript
// Check everything
const result = await mcp.call("check_setup");

// Check only Figma setup and auto-fix issues
const fixed = await mcp.call("check_setup", {
  focus: "figma",
  fix: true
});

Compliance Rules Reference

The check_compliance tool runs 12 rules against your code. Each rule returns violations with line references and suggested fixes. You can run all rules at once or target specific ones by ID.

Rule IDWhat It Checks
no-hardcoded-coloursFlags hex, rgb, and hsl colour values that should reference design tokens instead
use-design-tokensChecks that CSS properties use var(--token) references rather than raw values
no-hardcoded-spacingFlags pixel spacing values that are not on the design system's spacing scale (e.g. 4px grid)
no-unknown-componentsWarns when code references component names not found in the design system inventory
spacing-complianceValidates that margin, padding, and gap values match the token scale
font-family-complianceChecks that font-family declarations match the design system's typography tokens
border-radius-complianceValidates that border-radius values use the design system's radius tokens
interactive-state-coverageChecks that interactive elements have hover, focus, and disabled states defined
accessibility-alt-textFlags img elements missing alt attributes
accessibility-button-labelFlags button elements without accessible text content or aria-label
semantic-htmlChecks for semantic element usage (e.g. nav, main, section) instead of generic divs
motion-token-complianceValidates that transitions and animations reference motion tokens for duration and easing