# MCP Codegen Pipeline — Implementation Plan ## What's Done Branch `feat/mcp-codegen` (off `57eaf87`). ### New Files - `packages/core/src/tools/codegen.ts` — 3 MCP tools: - `design_to_tokens` — extracts Figma variables as CSS/Tailwind/JSON, resolves aliases, handles multi-mode - `design_to_component_map` — analyzes document for screens, components (variants, props, instance counts), dependency overview - `get_codegen_prompt` — returns the codegen system prompt (lazy `await import('node:fs/promises')` to avoid Vite browser externalization error) - `packages/core/src/tools/prompts/codegen.md` — 5-step workflow prompt (~8KB): 1. Survey (page tree, components, variables, colors, typography, spacing) 2. Decompose (clusters, describe, get_jsx → component map) 3. Extract tokens (stack-aware: Tailwind → only semantic color CSS vars; CSS → full vars) 4. Generate code (bottom-up, one file per component, interactive states) 5. Verify (re-check against design) - `packages/core/src/tools/registry.ts` — 3 tools registered in `ALL_TOOLS` (now 91 total) - `docs/design-to-code-overview.md` — architecture overview ### Design Decisions - **No MCP server instructions** — prompt delivered via `get_codegen_prompt` tool only (no 8KB overhead per request) - **Lazy fs import** — `await import('node:fs/promises')` inside function body to avoid Vite `Module "node:fs" has been externalized` crash in browser bundle - **Tailwind token strategy** — CSS custom properties only for semantic colors; Tailwind utilities for spacing/font/radius (avoids `--font-bold`, `--text-sm` conflicts with Tailwind v4 internals) - **No modifications to existing tools** — `get_jsx`, `describe`, `analyze_*` used as-is ### Tested - MCP HTTP server (`http://127.0.0.1:3100/mcp`) — all 3 new tools callable - End-to-end with `lol.fig` (Movie Card, 390×1823, Inter font, dark theme, 164 nodes): - Full pipeline: survey → decompose → tokens → generate → verify - Generated 10 Vue 3 + Tailwind components + semantic color tokens - Visual test in just-bun dev server ## What's Left ### Phase 1 — Tailwind HTML Export (high value, low effort) Add `format` parameter to `get_jsx` tool: - `"openpencil"` (default) — current round-trip JSX - `"tailwind"` — HTML with Tailwind v4 utility classes The renderer already exists (`export-jsx.ts` → `collectTailwindClasses`), just not exposed through the tool params. One change in `read.ts`. This gives the LLM ready-to-use HTML with correct Tailwind classes directly from MCP — drastically reduces hallucination in generated code. ### Phase 2 — Prompt Improvements - [ ] **Multi-file output format** — prompt should specify how to structure output when generating multiple files (fenced blocks with filenames) - [ ] **Framework adapters** — framework-specific sections in prompt (Vue `