Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:21st dev Magic mcp generate

From Leeroopedia
Knowledge Sources
Domains AI_Generation, UI_Components
Last Updated 2026-10-19 16:40 GMT

Overview

Concrete tool for generating brand-new UI from a natural-language description, provided by the 21st MCP server's hosted AI (reached through the proxy).

Description

The generate tool asks the 21st hosted AI to produce UI from a structured prompt (purpose, layout, content, style, stack). It consumes AI credits and returns a generation record with a `previewUrl` to view the result. It is listed by `tools/list` only when the account has AI access (`get_usage.aiGenerationEnabled === true`); builder/component access alone does not enable it.

Legacy names `21st_magic_component_builder` and `21st_magic_component_refiner` are still accepted server-side and translated to `generate` (the refiner produces a new generation from the refinement prompt, rather than mutating the old one).

This is an External Tool Doc: the signature below is reconstructed from `skills/21st-ui/SKILL.md` and `README.md`, not from in-repo source, because the tool implementation lives on the server.

Usage

Call `generate` when nothing in the catalog fits or the user explicitly wants custom UI, and only after verifying `get_usage.aiGenerationEnabled` and that `generate` is present in `tools/list`. Missing or unknown status is not permission to generate. If a cached call returns `ai_subscription_required`, stop generation attempts — do not retry through legacy aliases or the CLI.

Code Reference

Source Location

Signature

// JSON-RPC tool call, proxied to https://21st.dev/api/mcp
generate({
  purpose: string;   // what the UI is for
  layout?: string;    // layout constraints
  content?: string;   // text/data to render
  style?: string;     // visual style
  stack?: string;     // tech-stack constraints
}): {
  previewUrl: string;  // open to view the generation
  generationId: string; // pass to get_generation / get_take
};

Import

// Not imported. Call as an MCP tool through the 21st MCP server:
//   { "jsonrpc": "2.0", "id": <n>, "method": "tools/call",
//     "params": { "name": "generate",
//                 "arguments": { "purpose": "...", "layout": "...", ... } } }
// Legacy names still accepted server-side:
//   21st_magic_component_builder, 21st_magic_component_refiner → generate

I/O Contract

Inputs

Name Type Required Description
purpose string Yes What the UI is for
layout string No Layout constraints
content string No Text/data to render
style string No Visual style
stack string No Tech-stack constraints

Outputs

Name Type Description
previewUrl string URL to open and view the generation
generationId string Id for `get_generation` / `get_take` / iteration

Usage Examples

Generate a dashboard hero

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "generate",
    "arguments": {
      "purpose": "SaaS analytics dashboard hero with KPI cards",
      "layout": "3-column grid above a chart",
      "style": "dark, minimal",
      "stack": "React + Tailwind + shadcn"
    }
  }
}

Iterate on a draft (refinement)

{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "tools/call",
  "params": {
    "name": "generate",
    "arguments": {
      "purpose": "Refine the dashboard hero — add a revenue trend line below the KPIs",
      "stack": "React + Tailwind + shadcn"
    }
  }
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Notes

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment