Design, Brand & UI/UX

Design Systems for AI Agents: W3C Tokens, Figma MCP, and Visual Contracts

Hex palettes alone leave AI coding agents guessing button priority, surface roles, and focus contrast. Here is how W3C DTCG tokens, Figma MCP rules, and state contracts guide generation.

By Joana Vidal Design & Brand ~11 min

Open a settings panel generated by an AI coding agent that was handed a list of brand hex codes and a short prompt. At first glance, the screen looks tidy. The primary blue matches the brand swatch. The cards have rounded corners and neat drop shadows. Then you look as someone trying to complete a task.

In the bottom toolbar, “Save preferences” and “Reset workspace” sit side by side in the same cobalt fill, competing for the eye with identical weight. A secondary label inside an elevated card uses a cool gray that blurs into the background surface. When you press Tab to move through the form, the focus outline disappears behind a card border that happens to share the exact same stroke color.

Nothing in the prompt asked for a broken interface. The agent simply did what statistical code generation does when visual values arrive without functional responsibility: it filled in missing layout judgment with generic utility defaults.

Before touching a single CSS rule, a designer asks three quiet questions: where does the eye go first, what can the person actually identify or trigger, and which visual element carries a real responsibility on the screen? If a design system cannot answer those three questions in a format an AI agent can read, the agent will keep guessing.

Why raw hex palettes fail AI code generation

Raw values describe appearance, never intent. When a repository exposes --blue-600: #2563eb and --gray-400: #9ca3af in a stylesheet, an agent knows two colors exist, not what jobs they perform.

An agent has no visual memory of the brand; it only sees the names, types, descriptions, and component contracts in its context window. If a token file never declares which action is dominant, which is secondary, and which carries destructive risk, placing --blue-600 on two neighbouring buttons is a predictable outcome.

In our earlier article on bridging Figma Variables directly to Astro code, we covered build-time Style Dictionary compilation to stop manual handoff drift. Making a design system legible to AI agents adds a second discipline: encoding intent, pairing constraints, and component boundaries into machine-readable artifacts.

Structuring three-tier W3C DTCG tokens for machine reading

The Design Tokens Format Module 2025.10, published on 28 October 2025 by the W3C Design Tokens Community Group (DTCG), defines a vendor-neutral JSON format for design decisions. Formally, it is a Final Community Group Report intended as a stable implementation target, rather than a W3C Standards Track Recommendation.

For AI agents, the schema’s main strength is separating reserved metadata ($value, $type, $description, $extensions) from token hierarchy while supporting curly-brace aliases ({group.token}). A three-tier taxonomy establishes a clear chain of responsibility:

Token Tier Example Path What It Encodes Should an AI Agent Reference It Directly?
Tier 1: Primitive primitive.color.cobalt.600 Raw calibrated brand option (for example, OKLCH lightness, chroma, hue) No. Primitives carry appearance, not usage rules.
Tier 2: Semantic semantic.action.primary.bg Contextual role via alias ({primitive.color.cobalt.600}) and mode mapping Yes, for layout surfaces, text, borders, and spacing rhythm.
Tier 3: Component component.button.primary.focus-ring Scoped interactive contract for states where generic semantics are too broad Only via approved components or explicit state rules.

Notice how the W3C DTCG Color Module 2025.10 reinforces visual predictability as well. Rather than treating colors as opaque hex strings, the 2025.10 color specification represents them as structured objects with an explicit colorSpace (including "oklch", "srgb", "display-p3", and others) and numeric components. Because OKLCH separates perceptual lightness (0 to 1) from chroma and hue, an agent inspecting or generating paired foreground and background tokens works from values grounded in perceived brightness rather than deceptive sRGB math.

Similarly, DTCG dimension values require an explicit object with value and unit ("px" or "rem"). When spacing, radii, and border widths carry typed units instead of ambiguous numbers, an agent is far less likely to confuse a 2px focus stroke with a 0.5rem internal gap.

Treating $description as an agent instruction surface

Most teams leave $description empty or write circular notes like "Primary blue". That wastes one of the most reliable communication channels in the entire DTCG format.

Section 5.2.1 of the DTCG Format Module explicitly notes that style guide generators, IDEs, and translation tools can surface $description as tooltips or emit it as source code comments alongside compiled variables. When Style Dictionary or a custom build script preserves $description as a CSS comment right above each custom property, any AI agent reading the compiled stylesheet sees why a token exists and what it must pair with.

Compare two descriptions for the same semantic surface token:

  • Weak: "Card background color."
  • Operational: "Elevated card surface above canvas. Pair body copy with semantic.text.primary and muted labels with semantic.text.secondary; never place semantic.text.subtle on this surface."

The second string takes twenty seconds to write, costs zero runtime bytes, and removes ambiguity at the exact moment an agent selects text classes inside a card component. It turns documentation from a separate PDF nobody reads into an inline constraint attached to the token itself.

Wiring live context through the Figma MCP server and Code Connect

Tokens alone still leave an agent blind to component composition. A token file specifies button colors, yet an agent might still invent <div role="button"> with inline padding instead of importing the repository’s Button component.

The official Figma Model Context Protocol (MCP) server bridges visual frames and production code. Instead of pasting cropped screenshots into chat, an MCP-connected coding agent queries Figma directly through standardized MCP tools and prompts:

  1. get_design_context (or get_metadata first on larger selections to avoid truncated trees) to retrieve frame structure, auto layout constraints, and bound styles.
  2. get_variable_defs to inspect exact Figma variables and semantic names attached to that selection.
  3. get_screenshot to hold a visual reference of the intended variant before writing markup.

When Figma components map to code via Code Connect, the MCP server wraps recognized instances in <CodeConnectSnippet> markers with import paths, prop mappings, and custom guidance from “Add instructions for MCP”. Pair that with repository rules drafted via create_design_system_rules (Add custom rules and instructions) to forbid hardcoded hex overrides and require get_design_context plus get_screenshot before generation.

Separate two MCP roles cleanly: connecting an IDE agent to Figma operates at design and build time, carrying the credential and isolation considerations discussed in MCP server transports and sandboxing. Runtime browser interaction, where WebMCP (navigator.modelContext) exposes product actions to user assistants, belongs to the live application layer.

Where tokens and Figma context alone stop

Even with W3C DTCG tokens, Code Connect, and Figma MCP access, three interface failures still recur in agent-generated UI:

  1. Action hierarchy inflation: An agent may apply the primary button component three times in one modal or table header when Figma shows isolated variants without limiting dominant actions per view.
  2. Layout density collapse: When asked to “make the dashboard compact,” an agent often swaps space.card.padding for space.inline.tight, crowding labels and shrinking touch targets.
  3. Missing interactive and product states: Static Figma frames usually show resting defaults. Without explicit state tokens and product contracts, an agent often omits :focus-visible rings, skips loading locks, or exposes buttons a user lacks permission to trigger. As we examined in where generated controls end and product rules begin, drawing a balanced button does not establish whether the product permits that action in the current state.

A working W3C DTCG schema and compiled CSS contract

Here is a valid W3C DTCG 2025.10 token snippet using oklch colors, typed dimension objects, aliases, and operational $description rules:

{
  "primitive": {
    "color": {
      "cobalt": {
        "600": {
          "$type": "color",
          "$value": { "colorSpace": "oklch", "components": [0.52, 0.18, 258] },
          "$description": "Core brand cobalt. Reserve for semantic action mappings only."
        }
      },
      "neutral": {
        "50": {
          "$type": "color",
          "$value": { "colorSpace": "oklch", "components": [0.985, 0.004, 258] }
        },
        "200": {
          "$type": "color",
          "$value": { "colorSpace": "oklch", "components": [0.91, 0.008, 258] }
        },
        "900": {
          "$type": "color",
          "$value": { "colorSpace": "oklch", "components": [0.21, 0.015, 258] }
        }
      }
    },
    "space": {
      "200": {
        "$type": "dimension",
        "$value": { "value": 0.5, "unit": "rem" }
      },
      "600": {
        "$type": "dimension",
        "$value": { "value": 1.5, "unit": "rem" }
      }
    }
  },
  "semantic": {
    "surface": {
      "card": {
        "$type": "color",
        "$value": "{primitive.color.neutral.50}",
        "$description": "Card container fill. Pair with semantic.text.primary; separate from page canvas with semantic.border.decorative."
      }
    },
    "border": {
      "decorative": {
        "$type": "color",
        "$value": "{primitive.color.neutral.200}",
        "$description": "Subtle structural hairline for cards and dividers only. Never use for focus indicators."
      },
      "focus": {
        "$type": "color",
        "$value": "{primitive.color.cobalt.600}",
        "$description": "High-visibility functional keyboard focus ring. Always pair with 2px offset outside interactive controls."
      }
    },
    "action": {
      "primary-bg": {
        "$type": "color",
        "$value": "{primitive.color.cobalt.600}",
        "$description": "Single dominant action fill per view or footer. Pair with semantic.text.on-primary."
      }
    },
    "text": {
      "primary": {
        "$type": "color",
        "$value": "{primitive.color.neutral.900}",
        "$description": "Primary reading and label ink on canvas and card surfaces."
      },
      "on-primary": {
        "$type": "color",
        "$value": "{primitive.color.neutral.50}",
        "$description": "Text and icon ink placed strictly over semantic.action.primary-bg."
      }
    },
    "layout": {
      "card-padding": {
        "$type": "dimension",
        "$value": "{primitive.space.600}",
        "$description": "Minimum internal card padding on desktop and tablet layouts; do not substitute inline gap tokens."
      }
    }
  }
}

When compiled into CSS Custom Properties with comments preserved, the agent reads the exact contract inside the codebase without guessing:

:root {
  /* Elevated card fill. Pair with --semantic-text-primary. */
  --semantic-surface-card: oklch(0.985 0.004 258);

  /* Decorative hairline for cards/dividers only. Never use for focus rings. */
  --semantic-border-decorative: oklch(0.91 0.008 258);

  /* Functional keyboard focus ring with 2px offset outside interactive controls. */
  --semantic-border-focus: oklch(0.52 0.18 258);

  /* Single dominant action fill per view/footer. Pair with --semantic-text-on-primary. */
  --semantic-action-primary-bg: oklch(0.52 0.18 258);
  --semantic-text-on-primary: oklch(0.985 0.004 258);

  --semantic-layout-card-padding: 1.5rem;
}

Notice the operational distinction baked directly into those border tokens: decorative hairlines (--semantic-border-decorative) are explicitly separated from functional outlines (--semantic-border-focus). That prevents an agent from treating keyboard focus as a faint gray border tweak.

Machine-readable component and state rules

To cover what JSON tokens cannot enforce by themselves, pair your token files with a concise repository rule file (for example, in the custom instructions generated alongside create_design_system_rules) that states non-negotiable composition and state invariants:

  • Action hierarchy limit: A single card footer, dialog, or form bar may contain at most one variant="primary" button. Secondary actions must step down to secondary or ghost; destructive actions require an explicit danger variant separated visually from confirmation.
  • State completeness: Every interactive component generated from a Figma selection must implement default, hover, focus-visible (using --semantic-border-focus with a visible offset), disabled (explicitly noting why when action availability is blocked, never relying on opacity alone to convey system state), and loading (preserving button width to prevent layout shift).
  • Density floor: Card interiors must keep --semantic-layout-card-padding or the designated compact variant token; agents may not invent intermediate rem or px values when asked to “tighten” a layout.
  • Figma MCP sequence: Always run get_design_context and get_screenshot, check <CodeConnectSnippet> imports first, and refuse to emit raw hex codes (#...) in component styles.

Visual QA checks and separating taste from evidence

Before accepting any screen assembled by an AI agent, run a four-part visual inspection in the real rendered browser rather than judging code diffs alone:

  1. First-glance eye-path check: Blur your eyes or step back from the screen for two seconds. Can you immediately point to the single primary action without reading every button label? If two controls pull equal attention, demote the secondary one.
  2. Functional vs. decorative outline audit: Tab through every control with the keyboard only. Verify that decorative card borders stay quiet while functional focus rings remain unobstructed and clearly distinct from resting strokes across both light and dark modes.
  3. Computed contrast and state check: Inspect computed foreground-to-background contrast on muted labels, disabled hints, and hover states in browser DevTools. Treat algorithmic contrast checks (such as WCAG 2.2 AA 4.5:1 for normal text and 3:1 for UI components and focus indicators) as an engineering baseline to verify legibility, not as a substitute for full accessibility audits or legal certification.
  4. Design hypothesis vs. usability finding: Keep personal aesthetic judgment honest. Saying “reducing the secondary button to a quiet outline will stop people from hesitating before saving” is a visual hypothesis, not a measured conversion gain or a usability fact. Test that hypothesis by observing real users completing the task, checking whether hesitation, misclicks, or back-navigation actually drop. If users miss the secondary action during testing, your visual hypothesis was wrong, and the interface should change regardless of how clean the layout looked in Figma.

Design systems do not need to restrict creative composition to work with AI agents. When three-tier W3C DTCG tokens carry clear $description intent, Figma MCP connects live components through Code Connect, and repository rules protect hierarchy and interaction states, AI coding agents stop inventing arbitrary compromises and start extending the visual craft your team already defined.

[+] On this page 16 topics ▼
FAQ · Common Questions

Frequently Asked Questions

Why do AI coding agents produce generic UI even when given brand hex codes?

A raw hex code describes color appearance, not interface responsibility. Without semantic token roles, description constraints, and component mappings, an agent has to guess which color belongs to the dominant action, which belongs to a muted surface, and how text contrast holds across states.

Is the W3C Design Tokens Format Module 2025.10 a formal W3C Standard?

No. Published on 28 October 2025 as a Final Community Group Report by the W3C Design Tokens Community Group, it is a stable specification intended for implementation, not a formal W3C Standards Track Recommendation.

What does the Figma MCP server add beyond exporting JSON tokens?

The Figma MCP server exposes live design context, variable definitions, layout structure, screenshots, and Code Connect component snippets directly to coding agents, alongside project-level custom rules that prevent ad-hoc markup and hardcoded overrides.

Can design tokens alone control action hierarchy and layout density?

No. Tokens standardize visual values and semantic pairings, but they do not limit how many primary buttons appear in one footer or enforce keyboard focus, loading, and permission states. Those constraints require machine-readable component rules and visual QA.

Start your project

Need a website that earns trust, ranks in search, and gives your business a stronger digital presence? Start the conversation here.

Official sources used on this page