Principle:21st dev Magic mcp AI UI Generation
| Knowledge Sources | |
|---|---|
| Domains | AI_Generation, UI_Components |
| Last Updated | 2026-10-19 16:40 GMT |
Overview
A generation pattern that produces brand-new UI from a structured natural-language prompt (purpose, layout, content, style, stack) using a hosted AI model, when catalog search does not fit.
Description
AI UI generation is the act of asking a hosted AI model to author UI from an intent description rather than retrieving it from a catalog. It addresses the limitation of catalogs: when no existing component matches a novel design, the alternative is hand-coding from scratch, which is slow and inconsistent. A good generation call takes a structured prompt (what the UI is for, layout constraints, content, visual style, tech stack), consumes AI credits, and returns a preview plus a generation id for later reading and iteration. It is gated by an AI entitlement distinct from component/builder access, and a refusal (`ai_subscription_required`) is terminal for the session — it must not be retried through aliases or workarounds.
Usage
Use this principle when nothing in the catalog fits or the user explicitly wants custom UI, and only after verifying AI access (`get_usage.aiGenerationEnabled` and `generate` listed in `tools/list`). Missing or unknown status is not permission to generate. With AI off, fall back to catalog search + retrieval and adapt the code with your own coding agent.
Theoretical Basis
The core operation is a conditioned generation:
# Abstract algorithm description (NOT real implementation)
prompt = compose(purpose, layout, content, style, stack) # structured natural-language prompt
record = generate(prompt) # hosted model produces UI
# record = { previewUrl, generationId }
The model is hosted; the caller provides structure and constraints. Generation is non-deterministic; iteration calls `generate` again with a refinement prompt rather than mutating the prior output.
Practical Guide
- Verify AI access first — both `get_usage.aiGenerationEnabled` and `generate` in `tools/list`.
- Provide a structured prompt: `purpose`, `layout`, `content`, `style`, `stack`.
- Open the returned `previewUrl` to view the generation.
- To iterate, call `generate` again with a refinement prompt (a new generation).
- If a cached call returns `ai_subscription_required`, stop — do not retry through legacy aliases or the CLI. Refresh tools or reconnect after enabling AI.
- Read drafts back with `get_generation` / `get_take` (reads remain available with AI off).
Related Pages
Implemented By
Notes
- Gated by Principle:21st_dev_Magic_mcp_AI_Access_Verification — verify before calling.
- Drafts are read via Principle:21st_dev_Magic_mcp_Generation_Review.
- `generate` supersedes legacy `21st_magic_component_builder` / `21st_magic_component_refiner` (translated server-side).