thumbnail

Google Stitch MCP Tutorial β€” Generate React Components from AI Designs

Alex Hitt Β· 5:21
Google Stitch MCP Tutorial β€” Generate React Components from AI Designs
Google Stitch MCP React AI Design Code Generation Frontend

01 The Problem β€” Hallucinated UIs and Design Degradation

β–Ά 0:00

Early AI coding tools suffer from a fundamental flaw: they generate hallucinated generic UIs that break across screen sizes and ignore design intent. The root cause is that LLMs are probabilistic text generators β€” they approximate visual layouts rather than engineering them with precision.

The challenge Alex Hitt frames is clear: the industry needs to move from probabilistic text generation to deterministic, rigidly constrained UI engineering. The solution he walks through is building a local AI agent that pulls visual design data from the cloud, processes it through structured constraints, and outputs production-ready React components.

Prerequisites

  • Node.js 18+ β€” runtime for all Stitch tooling
  • Google Chrome β€” required for authentication flows
  • AI coding environment β€” Claude Code or Cursor
  • Active Google Stitch account β€” access at stitch.withgoogle.com
Bridging your local development environment directly to Google's cloud design models eliminates the friction of traditional design handoffs.

02 API Setup & Stitch MCP Initialization

β–Ά 0:56 – β–Ά 1:44

The first hands-on step is generating your API key. Navigate to the Stitch web console β†’ Profile β†’ Stitch Settings β†’ Generate new API key. This key authenticates your local machine against Google's generative infrastructure.

Initialization Command

npx @davideast/stitch-mcp init

The initialization wizard handles several critical tasks automatically:

  • Detecting and installing any missing Google Cloud dependencies
  • Configuring authentication flows with your API key
  • Registering your local machine as an authenticated node ready to pull high-fidelity visual data from Google's generative infrastructure
The init wizard is idempotent β€” running it multiple times won't duplicate configurations. It detects existing setups and only patches what's missing.

03 The MCP Proxy Connection β€” Why Not HTTP

β–Ά 1:44 – β–Ά 2:50

Official docs might suggest standard HTTP transport β€” DO NOT use it. Complex design generation requires massive data payloads. HTTP requests frequently drop packets or trigger connection timeouts, breaking generation entirely.

The correct approach is to bypass HTTP entirely and use the proxy command:

npx @davideast/stitch-mcp proxy

This creates a stable stdin/stdout stream directly between your IDE and the Stitch server. Instead of serializing design data into HTTP request/response cycles, the proxy maintains a persistent bidirectional pipe that ensures deterministic stability and no lost design tokens.

IDE Configuration

  • Claude Code: Paste the proxy command into your claude.json config file
  • Cursor: Paste into the MCP menu in the visual composer
Deterministic stability, ensuring no design tokens are lost.

04 Installing Stitch Skills

β–Ά 2:50 – β–Ά 3:39

Stitch Skills are structured knowledge packages that give the AI agent explicit frontend engineering capabilities. Install them with:

npx plugins add @google-labs-code/stitch-skills

Add the appropriate --scope and --target flags for your specific IDE.

Skill Library Structure

The skills are organized into a highly structured library across 3 macro directories:

  • Verticals β€” isolate specific tasks so concerns don't bleed across boundaries
  • Utility suite β€” handles standards enforcement, separated from production builds
  • Validation logic β€” provides the agent with explicit directory structures and validation rules for frontend engineering tasks
The skill library is what transforms a general-purpose LLM into a specialized frontend engineering agent. Without skills, the agent falls back to probabilistic guessing about project structure.

05 DESIGN.md β€” The Semantic Truth Document

β–Ά 3:39 – β–Ά 4:08

Before writing any React code, you must prevent the agent from hallucinating the aesthetic layout. This is done by generating a DESIGN.md file β€” a semantic truth document that locks in all design constraints.

Generating DESIGN.md

Run the design MD utility skill with the prompt:

"Analyze the Stitch project and generate a design.md"

The agent connects to the cloud, pulls all design data, and synthesizes a local document that explicitly locks in:

  • Exact typography families β€” no font substitution or guessing
  • Padding scales β€” precise spacing values from the design system
  • Color roles β€” semantic color assignments (primary, secondary, error, etc.)
The DESIGN.md forces the AI to obey these rules in all future steps β€” it's the contract between design intent and code output.

06 Converting Designs to React Components

β–Ά 4:08 – β–Ά 5:01

With the proxy connected, skills installed, and DESIGN.md generated, the final generation step is a single prompt:

"Convert all screens in the stitch project to react components"

What the Agent Does

The agent performs a multi-stage pipeline:

  1. Extracts raw HTML from the cloud design data
  2. Mathematically validates ASTs β€” abstract syntax trees are compared against the design spec
  3. Configures modular imports β€” establishes clean dependency graphs
  4. Writes JSX files β€” production-ready React components

Because the agent referenced the semantic truth document first, the generated components mirror the original cloud design without aesthetic degradation.

Verification

npx @davideast/stitch-mcp serve

This spins up a local Vite dev environment where you can inspect the generated components visually. From here, you can issue surgical natural language commands:

  • "Add a checkbox to the form component"
  • "Alter the hover color state on the navigation"

These modifications are applied without destabilizing the surrounding UI architecture because the agent always references the DESIGN.md constraints.

07 Stitch Loop β€” Automated Multi-Page Generation

β–Ά 5:01 – β–Ά 5:21

The final capability Alex demonstrates is Stitch Loop β€” an automation mode that handles end-to-end generation of complex multi-page applications completely unattended.

Instead of issuing one prompt per screen, Stitch Loop iterates through all pages in the design project, generating components, validating them against DESIGN.md, and assembling the full application structure automatically.

Removes the need for manual pixel reconciliation.

With Stitch Loop handling the repetitive generation work, developers can shift their focus to what matters most: business logic and overall architecture. The pixel-perfect UI layer is handled deterministically by the pipeline.

🎯 Key Takeaways

  1. Google Stitch MCP bridges cloud design tools with local AI coding agents for deterministic UI generation β€” eliminating the hallucinated UI problem.
  2. Use stdin/stdout proxy, not HTTP β€” HTTP drops packets on large design payloads, breaking generation. The proxy command ensures stable, lossless communication.
  3. DESIGN.md acts as a "semantic truth document" that locks in typography, spacing, and color constraints before any code is generated.
  4. Stitch Skills give the agent structured frontend engineering knowledge β€” directory structures, validation logic, and standards enforcement.
  5. Generated React components mathematically validate against original designs via AST comparison, ensuring zero aesthetic degradation.
  6. Stitch Loop enables fully automated multi-page application generation, removing manual pixel reconciliation from the workflow.

πŸ“š Resources & Links

⏱️ Timestamp Index

TimeSection
β–Ά 0:00The Problem β€” Hallucinated UIs and Design Degradation
β–Ά 0:56API Setup & Stitch MCP Initialization
β–Ά 1:44The MCP Proxy Connection β€” Why Not HTTP
β–Ά 2:50Installing Stitch Skills
β–Ά 3:39DESIGN.md β€” The Semantic Truth Document
β–Ά 4:08Converting Designs to React Components
β–Ά 5:01Stitch Loop β€” Automated Multi-Page Generation