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

Environment:21st dev Magic mcp shadcn Project

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

Overview

A host project set up for shadcn (Tailwind, `cn` helper, `components.json`) into which a 21st.dev catalog component is installed via `shadcn registry add`.

Description

This environment is the user's own project, not anything in this repo. 21st.dev catalog components are shadcn-compatible React/Tailwind components, so installing one via the `shadcn registry add` CLI requires the target project to already be a shadcn project: a configured Tailwind setup, the `cn` class-merge helper, and a `components.json` manifest that tells the CLI where to write files and how to resolve aliases.

When a Implementation:21st_dev_Magic_mcp_get_component result's `installInstructions` say to use registry add, the agent runs `npx shadcn@latest add <registry-url>` in the host project; the CLI reads `components.json`, writes the component files into the configured folder, and wires the `cn`/Tailwind tokens. If the project is not set up for shadcn, the CLI will fail — in that case the agent should fall back to writing the files returned by `get_component` directly and wiring them by hand.

Usage

Use this environment when a `get_component` result instructs a registry-add install. It is the prerequisite for Implementation:21st_dev_Magic_mcp_shadcn_registry_add. If the host project is not a shadcn project, do not use registry add — write the returned files directly instead.

System Requirements

Category Requirement Notes
Project type React + Tailwind 21st.dev components are shadcn-compatible React/Tailwind
Config `components.json` at project root Tells the CLI the component folder, aliases, and style
Helper `cn` (clsx + tailwind-merge) Required by shadcn components for class merging
Runtime Node 18+ To run `npx shadcn@latest add`
Network Outbound HTTPS to the registry URL Usually `https://21st.dev/r/<component>.json`

Dependencies

Project-side (required before `shadcn add` works)

  • `tailwindcss` (configured; `tailwind.config.*` present)
  • `clsx` + `tailwind-merge` (backing the `cn` helper)
  • `cn` helper exported (typically `src/lib/utils.ts`)
  • `components.json` (shadcn manifest) at project root

CLI (invoked via npx, not a fixed dep)

  • `shadcn` (latest) — `npx shadcn@latest add <url>` fetches and writes the component

Credentials

  • None for the registry URL itself (21st.dev registry endpoints are public for component JSON). The `x-api-key` 21st key is used by `get_component` upstream to retrieve the install instructions, not by `shadcn add` itself.

Quick Install

# One-time: set up shadcn in a React + Tailwind project (if not already):
npx shadcn@latest init

# Then, per get_component instructions:
npx shadcn@latest add "https://21st.dev/r/<component>.json"
# Wire the imported component into your page; adapt tokens/props to fit.

Code Evidence

The skill file directs registry add and names the prerequisites — `skills/21st-ui/SKILL.md:24`:

4. Install into the project the way the result instructs (shadcn-style registry add
   or by writing the returned files), then wire it into the page and adapt
   tokens/props to the project's design system.

The implementation page requires this environment — `implementations/21st_dev_Magic_mcp_shadcn_registry_add.md:94-95`:

=== Requires Environment ===
* [[requires_env::Environment:21st_dev_Magic_mcp_shadcn_Project]]

The CLI signature from the shadcn docs, as quoted in `implementations/21st_dev_Magic_mcp_shadcn_registry_add.md:42-47`:

# Install a component from a registry URL or specifier.
npx shadcn@latest add <registry-url-or-specifier>
# e.g. for a 21st.dev registry component:
npx shadcn@latest add "https://21st.dev/r/<component>.json"

Common Errors

Error Message Cause Solution
`Could not find components.json` Project is not shadcn-initialized Run `npx shadcn@latest init`, or fall back to writing the `get_component` files directly
`Cannot find module 'cn'` / `utils` alias unresolved `components.json` aliases wrong, or `cn` helper missing Create `src/lib/utils.ts` exporting `cn` (clsx + tailwind-merge) and fix the `aliases` in `components.json`
Component styles unstyled / Tailwind classes missing Tailwind not configured, or content globs miss the new files Add the component folder to `tailwind.config` `content`, or re-run `shadcn init`
Registry URL 404 / fetch error Wrong registry URL from `get_component`, or network blocked Re-copy the `installInstructions` URL; allow HTTPS to 21st.dev

Compatibility Notes

  • Non-shadcn projects: Registry add will fail. Use the `files` array from `get_component` directly and wire by hand — the result supports both paths.
  • Tailwind v4 vs v3: shadcn's CLI handles both, but the project's `components.json` and `tailwind.config` must match the Tailwind version in use.
  • Path aliases: `components.json` `aliases` (`@/components`, `@/lib/utils`, ...) must resolve in the project's bundler (`tsconfig` paths / Vite / Next.js). Mismatched aliases break imports inside the installed component.
  • Prettier/formatting: shadcn writes files in its own style; run the project formatter after install if needed.

Related Pages

Page Connections

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