Skip to content
All posts

Engineering

Build a Custom shadcn Registry and Connect It via MCP

Build a custom shadcn registry modeled on TentUI's @tentui setup: registry.json, namespaces, transitive deps, CLI view checks, llms.txt, and MCP.

SS
Sourabh Soni

To build a custom shadcn registry, define your items against the official shadcn/schema, compile them into static JSON files under /r/{name}.json with shadcn build, validate the output, and publish a namespace URL template that consumers add to components.json. Once those JSON endpoints are live, the official shadcn MCP server (npx shadcn@latest mcp init) can search, inspect, and install your components directly from Claude Code, Cursor, and other AI editors with no custom MCP server code required.

This guide walks through the exact architecture behind TentUI's live @tentui registry—covering registry:component vs registry:block, transitive registryDependencies, pre-install verification with shadcn view, and pairing the registry with llms.txt and MCP so both humans and coding agents get reliable source code.

When a custom shadcn registry beats an npm package

Publishing an internal or public UI library to npm is the right call for low-level, versioned primitives whose internal DOM rarely changes. For product components, animated interactions, and multi-file page blocks, a shadcn registry gives teams a cleaner boundary: consumers receive editable TypeScript source in their own repo, with zero runtime wrapper package to upgrade in lockstep.

That source-ownership trade-off is explored in Why copy-paste components scale. A custom registry turns copy-paste from ad-hoc gists into a repeatable, schema-validated distribution pipeline.

Define your registry items (registry:component vs registry:block)

In TentUI, the registry manifest starts in TypeScript (src/registry/index.ts) validated with Registry and registrySchema from shadcn/schema. Splitting items by purpose keeps large catalogs maintainable:

src/registry/index.ts
import type { Registry } from "shadcn/schema";
 
import { blocks } from "./blocks/_registry";
import { components } from "./components/_registry";
import { examples } from "./examples/_registry";
 
export const registry = {
  name: "tentui",
  homepage: "https://tentui.com",
  items: [...blocks, ...components, ...examples],
} satisfies Registry;

Choosing the right item type matters because it tells both the CLI and reviewers how much code an install will introduce:

Registry typeBest fitTypical filesExample in TentUI
registry:componentA focused interactive control plus any local helpers or hooks1–3 files (@components/..., @hooks/...)copy-button, snap-sheet, stateful-button
registry:blockA complete page section or multi-route layout composing primitives1–4+ files (@components/..., app/..., @lib/...)hero-02, pricing-03, 404-01, legal-page-01
registry:hook / registry:libShared utilities or hooks installed inside a component or standalone1 file (@hooks/..., @lib/...)use-copy-to-clipboard.ts, webgl.ts
registry:exampleInternal docs demos; filtered out of public registry.json1 demo filesnap-sheet-demo

A real component item in TentUI declares its npm packages, official shadcn primitives, and exact file targets. Here is how @tentui/copy-button bundles its component, animation helper, and clipboard hook as one installable unit:

src/registry/components/_registry.ts
{
  name: "copy-button",
  type: "registry:component",
  title: "Copy Button",
  description: "Copy text to the clipboard with visual, sound, and haptic feedback.",
  dependencies: ["@rexa-developer/tiks", "lucide-react", "motion", "web-haptics"],
  registryDependencies: ["button"],
  files: [
    {
      path: "components/copy-button/copy-button.tsx",
      type: "registry:component",
      target: "@components/copy-button.tsx",
    },
    {
      path: "components/icon-swap/icon-swap.tsx",
      type: "registry:component",
      target: "@components/icon-swap/icon-swap.tsx",
    },
    {
      path: "src/hooks/use-copy-to-clipboard.ts",
      type: "registry:hook",
      target: "@hooks/use-copy-to-clipboard.ts",
    },
  ],
  docs: "https://tentui.com/components/copy-button",
}

Notice the target aliases (@components/..., @hooks/..., @lib/...). They let the CLI respect each consumer's components.json path aliases instead of hardcoding src/components/.

Wire transitive registryDependencies cleanly

Blocks and composite components often depend on both official shadcn primitives (like "button" or "card") and other items in your own custom registry.

For official shadcn items, use the plain name ("button", "accordion"). For items from your own registry, pass the full item URL (or configured namespace) so the CLI resolves them even when the consumer installed a block via direct URL without configuring your namespace first.

In TentUI, a tiny helper (getRegistryItemUrl) generates those URLs from one config constant (https://tentui.com/r/{name}.json):

src/registry/blocks/_registry.ts
{
  name: "hero-02",
  title: "Hero 02",
  type: "registry:block",
  registryDependencies: [
    "button",
    getRegistryItemUrl("brand-context-menu"),
    getRegistryItemUrl("peeping-button"),
  ],
  files: [
    {
      path: "blocks/hero-02/hero-02.tsx",
      target: "@components/hero-02/index.tsx",
      type: "registry:component",
    },
    {
      path: "blocks/hero-02/header.tsx",
      target: "@components/hero-02/header.tsx",
      type: "registry:component",
    },
  ],
}

When someone runs npx shadcn@latest add @tentui/hero-02, the CLI walks that graph automatically: hero-02 pulls in brand-context-menu, which in turn pulls in context-menu and copy-button, installing every required file and npm dependency in one pass.

Build and validate static /r/{name}.json artifacts

A shadcn registry does not need a database or dynamic API route to serve items. Static JSON files in public/r/ are fast, cacheable at the edge, and immune to runtime cold starts.

TentUI's build pipeline (package.json) runs two commands in sequence and then validates the compiled output:

package.json
{
  "scripts": {
    "registry:build": "tsx ./scripts/build-registry.mts && shadcn build",
    "registry:validate": "shadcn registry validate ./public/r/registry.json"
  }
}

Here is what each step does:

  1. scripts/build-registry.mts validates the TypeScript manifest with registrySchema.safeParse(), filters out internal registry:example items, normalizes relative paths (src/registry/...), and writes the top-level registry.json manifest (along with pre-built docs indexes).
  2. shadcn build reads registry.json, inlines each file's source code into its own JSON payload under public/r/<name>.json, and writes public/r/registry.json as the index.
  3. shadcn registry validate ./public/r/registry.json verifies that every generated payload conforms to the registry schema before you deploy.

One subtle hosting pitfall: make sure missing /r/*.json paths return a real 404 JSON or plain-text error, never a 200 OK HTML SPA fallback. As detailed in Shadcn Missing Components: Find and Install Them Safely, an HTML fallback triggers the infamous Unexpected token '<' CLI error and hides broken item names.

Configure custom namespaces in components.json

Once public/r/{name}.json is deployed on your domain, consumers register your namespace once in components.json:

components.json
{
  "registries": {
    "@tentui": "https://tentui.com/r/{name}.json"
  }
}

The CLI substitutes {name} for every command under that namespace. Consumers can also install a single item without touching components.json by passing the full URL:

pnpm dlx shadcn@latest add https://tentui.com/r/copy-button.json

For full consumer setup steps—including manual fallback and updating copied source—see the TentUI installation guide.

Always support npx shadcn@latest view inspection

Before adding third-party source to a production repo, developers (and security reviewers) should inspect what the registry will write without modifying disk:

pnpm dlx shadcn@latest view @tentui/snap-sheet

view prints the exact JSON payload: description, dependencies, registryDependencies, file targets, and full source contents. Keeping your registry descriptions accurate, avoiding hidden dependencies, and using clean target paths makes view output immediately trustworthy.

You can also verify searchability against your published registry.json index:

pnpm dlx shadcn@latest search @tentui -q "sheet"

If search returns empty results, double-check that public/r/registry.json is published at the same /r/ root as your individual {name}.json files and includes concise, keyword-clear title and description fields for every item.

Connect your registry to AI editors with llms.txt and MCP

Modern discovery happens inside editors as often as in browser search. A custom shadcn registry works with the official shadcn MCP server out of the box as soon as two things are in place:

  1. A configured namespace in components.json pointing to your /r/{name}.json endpoint (with a valid /r/registry.json index).
  2. Initialized MCP config in the consumer's project:
pnpm dlx shadcn@latest mcp init

After running mcp init (and choosing Claude Code, Cursor, or another MCP client in the prompt), the AI assistant can search your @namespace, view item source, and install components with the right dependencies. TentUI's MCP setup guide shows the exact consumer workflow.

To make AI assistants even more accurate when they read your documentation directly, pair the registry with machine-readable Markdown endpoints:

  • /llms.txt — A compact index listing your namespace configuration, every component's one-sentence summary, its exact npx shadcn@latest add @tentui/<name> command, and a link to its raw .mdx doc.
  • /llms-full.txt — The full component docs and guides concatenated for tools that prefer a single context fetch.
  • Per-page .mdx routes and Accept: text/markdown negotiation — In TentUI, requesting /components/snap-sheet.mdx (or sending Accept: text/markdown to /components/snap-sheet) returns clean Markdown instead of HTML navigation chrome.

Together, registry.json (for structured MCP tool calls) and llms.txt (for documentation and usage context) let coding agents pick the right component, install it cleanly, and wire its props without hallucinating APIs.

Pre-publish checklist for custom registry authors

Before announcing a custom shadcn registry, run through these checks against your deployed URL:

CheckCommand or verification
Schema validationnpx shadcn@latest registry validate ./public/r/registry.json
Payload inspectionnpx shadcn@latest view https://your-domain.com/r/<item>.json
Clean-room installRun npx shadcn@latest add @your-ns/<item> in a fresh Next.js + Tailwind project
Transitive graphInstall a multi-file registry:block and verify nested registryDependencies resolve
Missing item statuscurl -I https://your-domain.com/r/does-not-exist.json returns 404, not 200 HTML
MCP discoveryRun npx shadcn@latest mcp init and prompt your editor to search and add one item
License clarityState clearly whether items are MIT, free and source-available, or commercial

FAQ

How does a custom shadcn registry work?

A custom shadcn registry is a set of static JSON files following the official shadcn/schema hosted at a URL template such as https://example.com/r/{name}.json, alongside a registry.json index. When a user runs npx shadcn@latest add @namespace/item, the CLI fetches that JSON, installs declared npm and registry dependencies, and writes the source files into the project's configured alias paths.

What is the difference between registry:component and registry:block?

Use registry:component for a focused, reusable UI control and its supporting hook or helper files, and use registry:block for larger multi-part page sections or route layouts (such as a hero, pricing section, or 404 page) that compose multiple primitives and may include framework-specific files.

Do I need to build a custom MCP server for my shadcn registry?

No. The official shadcn CLI ships an MCP server (npx shadcn@latest mcp init) that reads any registry configured in components.json. As long as your registry serves valid /r/registry.json and /r/{name}.json endpoints with clear titles and descriptions, Claude Code, Cursor, and other MCP clients can search and install your items immediately.

How should I declare dependencies between items in my own registry?

List official shadcn primitives by name (such as "button") in registryDependencies, and reference other items from your custom registry by their full item URL (such as https://tentui.com/r/animated-tabs.json). That ensures transitive dependencies resolve even if a consumer installs an item by direct URL without adding your namespace to components.json.

How can consumers inspect a custom registry item before installing it?

Run npx shadcn@latest view @namespace/<item> (or pass the full .json URL). The CLI prints the item's metadata, dependencies, target paths, and complete source code without writing any files to disk.

Why should a custom registry also expose llms.txt?

registry.json gives MCP tools the file payloads and install metadata, while llms.txt gives AI assistants and documentation scrapers a concise map of every component, its install command, and links to raw Markdown docs with usage examples, accessibility notes, and prop guidance.

Components in this guide

All components
All posts
Follow new React and shadcn/ui component releases.