/ 目录 / 演练场 / 21st.dev Magic MCP
● 官方 21st-dev ⚡ 即开即用

21st.dev Magic MCP

作者 21st-dev · 21st-dev/magic-mcp

Generate beautiful React components inline — like v0, but inside your editor.

Magic MCP is 21st.dev's component generator: ask in plain English, get a production-quality React + Tailwind component returned inline. Works in Cursor, Claude Code, Windsurf — anywhere MCP runs.

为什么要用

核心特性

实时演示

实际使用效果

magic-mcp.replay ▶ 就绪
0/0

安装

选择你的客户端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "magic-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@21st-dev/magic@latest"
      ]
    }
  }
}

打开 Claude Desktop → Settings → Developer → Edit Config。保存后重启应用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "magic-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@21st-dev/magic@latest"
      ]
    }
  }
}

Cursor 使用与 Claude Desktop 相同的 mcpServers 格式。项目级配置优先于全局。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "magic-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@21st-dev/magic@latest"
      ]
    }
  }
}

点击 Cline 侧栏中的 MCP Servers 图标,然后选 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "magic-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@21st-dev/magic@latest"
      ]
    }
  }
}

格式与 Claude Desktop 相同。重启 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "magic-mcp",
      "command": "npx",
      "args": [
        "-y",
        "@21st-dev/magic@latest"
      ]
    }
  ]
}

Continue 使用服务器对象数组,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "magic-mcp": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "@21st-dev/magic@latest"
        ]
      }
    }
  }
}

加入 context_servers。Zed 保存后热重载。

claude mcp add magic-mcp -- npx -y @21st-dev/magic@latest

一行命令搞定。用 claude mcp list 验证,claude mcp remove 卸载。

使用场景

实战用法: 21st.dev Magic MCP

Generate a polished landing-page hero in under a minute

👤 Frontend engineers shipping fast ⏱ ~15 min intermediate

何时使用: You need a hero section right now and don't want to start from a blank file.

前置条件
  • Server/skill installed and authenticated — See repo README
步骤
  1. Search for inspiration
    Search 21st for hero sections that mix gradient + product screenshot.✓ 已复制
    → 5–10 starter components
  2. Generate the final one
    Create a Hero component: dark gradient bg, headline 'Ship faster.' subhead 'AI for serious teams.' a primary CTA + secondary CTA, social proof row.✓ 已复制
    → A complete tsx file using shadcn primitives

结果: A real production-shape component in one prompt.

注意事项
  • Generated components assume shadcn primitives are installed — Generated components assume shadcn primitives are installed — run npx shadcn add button card first.
搭配使用: filesystem · flyonui-mcp

组合

与其他 MCP 搭配,撬动十倍杠杆

magic-mcp + filesystem

Pair with filesystem for complementary capabilities

Use this server together with filesystem to complete a multi-step task.✓ 已复制
magic-mcp + flyonui-mcp

Pair with flyonui-mcp for complementary capabilities

Use this server together with flyonui-mcp to complete a multi-step task.✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
create_component description, framework Need a new UI component 21st credits
refine_component component_code, instruction Tweak an existing component 21st credits
search_components query Find a pre-made starting point 1 API call

成本与限制

运行它的成本

API 配额
See provider docs for rate limits
每次调用 Token 数
Varies by tool
费用
See repo README for pricing details
提示
Cache tool results and avoid repeated identical calls.

安全

权限、密钥、影响范围

凭据存储: Use environment variables; never commit secrets
数据出站: Tool calls go to the provider's API as documented

故障排查

常见错误与修复

API key invalid

Get a key at 21st.dev/settings/api and set TWENTY_FIRST_API_KEY.

验证: search_components returns results
component uses missing shadcn import

Run npx shadcn add <component> for each unresolved import.

验证: Vite/Next builds cleanly

替代方案

21st.dev Magic MCP 对比其他方案

替代方案何时用它替代权衡
v0.devYou prefer the v0 web UIOutside your editor; different style

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills