MCP server integration for AI assistant workflows. The Model Context Protocol (MCP) server enables AI assistants to discover, search, view, and add components through a standardized protocol.
The MCP server instance that AI assistants can connect to for component management operations.
/**
* MCP Server instance for AI assistant integration
* Provides tools for component discovery and management
*
* Note: Server type is from '@modelcontextprotocol/sdk/server/index.js'
*/
const server: Server
// Server is the MCP server class from the Model Context Protocol SDK
// It provides a standardized interface for AI assistants to interact with tools
interface Server {
// MCP server properties and methods (from @modelcontextprotocol/sdk)
// Details: https://github.com/modelcontextprotocol/typescript-sdk
}Usage Example:
import { server } from 'shadcn/mcp';
// The server is pre-configured and ready to use
// Typically used by running: npx shadcn mcpServer Lifecycle:
npx shadcn mcp is executedThe MCP server provides 7 specialized tools for AI assistants:
Gets configured registry names from components.json. Returns an error if no components.json exists.
/**
* Tool: get_project_registries
* Description: Get configured registry names from components.json
* Parameters: none
* Returns: List of configured registry names with usage instructions
*/
{
name: "get_project_registries"
inputSchema: {
type: "object"
properties: {}
required: []
}
}Parameters: None
Returns: Text message with:
Usage Scenario:
AI assistant asks: "What registries are configured in this project?"
MCP response includes:
@shadcn registry@acme registry (if configured)npx shadcn view @shadcnSuccess Response Format:
{
"content": [{
"type": "text",
"text": "Configured registries:\n- @shadcn\n- @acme\n\nUsage: npx shadcn view @shadcn"
}],
"isError": false
}Error Cases:
initError Response Format:
{
"content": [{
"type": "text",
"text": "Error: components.json not found\n\n💡 Run: npx shadcn init"
}],
"isError": true
}Edge Cases:
Lists items from specified registries. Requires components.json to be configured.
/**
* Tool: list_items_in_registries
* Description: List items from registries
* Parameters:
* - registries: Array of registry names (e.g., ['@shadcn', '@acme'])
* - limit: Maximum items to return (optional, default: 100)
* - offset: Pagination offset (optional, default: 0)
* Returns: Paginated list of items with names, types, and descriptions
*/
{
name: "list_items_in_registries"
inputSchema: {
type: "object"
properties: {
registries: {
type: "array"
items: { type: "string" }
description: "Array of registry names to list (must start with @)"
minItems: 1
}
limit: {
type: "number"
description: "Maximum number of items to return"
minimum: 1
maximum: 1000
default: 100
}
offset: {
type: "number"
description: "Number of items to skip for pagination"
minimum: 0
default: 0
}
}
required: ["registries"]
}
}Parameters:
registries: string[] - Array of registry names to list (e.g., ['@shadcn', '@acme']). Must start with @. Required.limit?: number - Maximum number of items to return (1-1000, default: 100). Optional. Values above 1000 are clamped to 1000.offset?: number - Number of items to skip for pagination (minimum: 0, default: 0). Optional. Negative values result in validation error.Returns: Formatted list of items with:
Usage Example:
AI assistant: "List all components from @shadcn"
MCP request:
{
"registries": ["@shadcn"],
"limit": 20
}MCP response includes:
Pagination Example:
{
"content": [{
"type": "text",
"text": "Items from @shadcn:\n\n1. button (registry:ui) - A button component\n2. card (registry:ui) - A card component\n...\n\nPagination: Showing 1-20 of 150 items (hasMore: true)"
}],
"isError": false
}Error Cases:
@) → Validation error with format requirementEdge Cases:
Searches for components in registries using fuzzy matching. Requires components.json.
/**
* Tool: search_items_in_registries
* Description: Search for components using fuzzy matching
* Parameters:
* - registries: Array of registry names to search
* - query: Search query string
* - limit: Maximum items to return (optional, default: 10)
* - offset: Pagination offset (optional, default: 0)
* Returns: Paginated search results with fuzzy matching
*/
{
name: "search_items_in_registries"
inputSchema: {
type: "object"
properties: {
registries: {
type: "array"
items: { type: "string" }
description: "Array of registry names to search (must start with @)"
minItems: 1
}
query: {
type: "string"
description: "Search query for fuzzy matching on names and descriptions"
minLength: 1
}
limit: {
type: "number"
description: "Maximum number of items to return"
minimum: 1
maximum: 100
default: 10
}
offset: {
type: "number"
description: "Number of items to skip for pagination"
minimum: 0
default: 0
}
}
required: ["registries", "query"]
}
}Parameters:
registries: string[] - Array of registry names to search. Must start with @. Required.query: string - Search query for fuzzy matching (minimum length: 1). Required. Empty strings result in validation error.limit?: number - Maximum items to return (1-100, default: 10). Optional. Values above 100 are clamped to 100.offset?: number - Pagination offset (minimum: 0, default: 0). Optional.Returns: Search results with:
get_item_examples_from_registries for usage examplesUsage Example:
AI assistant: "Search for button components"
MCP request:
{
"registries": ["@shadcn"],
"query": "button"
}MCP response includes:
Fuzzy Matching Behavior:
Error Cases:
isError: false)Edge Cases:
limit parameterViews detailed information about specific registry items. Shows item metadata, files, and code.
/**
* Tool: view_items_in_registries
* Description: View detailed information about registry items
* Parameters:
* - items: Array of item names with registry prefix
* Returns: Detailed item information including files and content
* Note: For usage examples, use get_item_examples_from_registries instead
*/
{
name: "view_items_in_registries"
inputSchema: {
type: "object"
properties: {
items: {
type: "array"
items: { type: "string" }
description: "Array of item names with registry prefix (e.g., '@shadcn/button')"
minItems: 1
}
}
required: ["items"]
}
}Parameters:
items: string[] - Array of item names with registry prefix (e.g., ['@shadcn/button', '@shadcn/card']). Must include registry prefix. Required, minimum 1 item.Returns: Detailed information including:
Usage Example:
AI assistant: "Show me the button component"
MCP request:
{
"items": ["@shadcn/button"]
}MCP response includes:
Response Structure:
{
"content": [{
"type": "text",
"text": "Item: @shadcn/button\nType: registry:ui\nDescription: A button component\n\nFiles:\n- components/ui/button.tsx\n\nDependencies:\n- class-variance-authority\n- @radix-ui/react-slot\n\nRegistry Dependencies:\n- utils"
}],
"isError": false
}Error Cases:
Edge Cases:
Finds usage examples and demos with complete code. Searches for demo and example items.
/**
* Tool: get_item_examples_from_registries
* Description: Find usage examples and demos with complete implementation code
* Parameters:
* - registries: Array of registry names to search
* - query: Search query for examples (e.g., 'accordion-demo', 'button example')
* Returns: Complete example code with dependencies
* Common patterns: '{item-name}-demo', '{item-name} example', 'example {item-name}'
*/
{
name: "get_item_examples_from_registries"
inputSchema: {
type: "object"
properties: {
registries: {
type: "array"
items: { type: "string" }
description: "Array of registry names to search (must start with @)"
minItems: 1
}
query: {
type: "string"
description: "Search query for examples (e.g., 'accordion-demo', 'button example')"
minLength: 1
}
}
required: ["registries", "query"]
}
}Parameters:
registries: string[] - Array of registry names to search. Must start with @. Required.query: string - Search query for examples (e.g., 'accordion-demo', 'button example'). Minimum length: 1. Required.Returns: Example code and metadata:
Common Query Patterns:
{component-name}-demo (e.g., accordion-demo){component-name} demo (e.g., button demo){component-name} example (e.g., card example)example {component-name} (e.g., example form)Usage Example:
AI assistant: "Show me button examples"
MCP request:
{
"registries": ["@shadcn"],
"query": "button-demo"
}MCP response includes:
Error Cases:
search_items_in_registries firstsearch_items_in_registries and then view_items_in_registriesFallback Strategy:
{component}-demo{component} demo{component} example{component} examplessearch_items_in_registries first to find example itemsEdge Cases:
Gets the shadcn CLI add command for specific items. Returns the exact command to add components.
/**
* Tool: get_add_command_for_items
* Description: Get the CLI add command for specific items
* Parameters:
* - items: Array of items to add with registry prefix
* Returns: The exact npx shadcn add command to run
*/
{
name: "get_add_command_for_items"
inputSchema: {
type: "object"
properties: {
items: {
type: "array"
items: { type: "string" }
description: "Array of items to add with registry prefix (e.g., '@shadcn/button')"
minItems: 1
}
}
required: ["items"]
}
}Parameters:
items: string[] - Array of items to add with registry prefix (e.g., ['@shadcn/button', '@shadcn/card']). Must include registry prefix. Required, minimum 1 item.Returns: The exact CLI command to add the items
Usage Example:
AI assistant: "How do I add the button and card components?"
MCP request:
{
"items": ["@shadcn/button", "@shadcn/card"]
}MCP response:
{
"content": [{
"type": "text",
"text": "npx shadcn add @shadcn/button @shadcn/card"
}],
"isError": false
}Command Format:
npx shadcn add @shadcn/buttonnpx shadcn add @shadcn/button @shadcn/cardnpx shadcn add button card (if @shadcn is default)Error Cases:
search_items_in_registries firstEdge Cases:
Gets a checklist for verifying components after creation. Provides post-addition verification steps.
/**
* Tool: get_audit_checklist
* Description: Get checklist for verifying components after creation
* Parameters: none
* Returns: Checklist of common issues to verify
* Note: Use after all required steps have been completed
*/
{
name: "get_audit_checklist"
inputSchema: {
type: "object"
properties: {}
required: []
}
}Parameters: None
Returns: Checklist including:
Usage Example:
AI assistant: "I've added the button component. What should I check?"
MCP request:
{}MCP response provides the complete audit checklist.
Checklist Items:
Response Format:
{
"content": [{
"type": "text",
"text": "Post-Installation Checklist:\n\n[ ] Ensure imports are correct (named vs default imports)\n[ ] If using next/image, ensure images.remotePatterns in next.config.js is configured\n[ ] Ensure all dependencies are installed\n[ ] Check for linting errors or warnings\n[ ] Check for TypeScript errors\n[ ] Use Playwright MCP if available"
}],
"isError": false
}Note: This tool always succeeds and returns the same checklist. It does not validate the actual installation state.
Start the MCP server from the command line:
npx shadcn mcpThe server runs on stdio and waits for MCP protocol messages from AI assistants.
Server Behavior:
import { server } from 'shadcn/mcp';
// Server is already configured and ready
// Request handlers are pre-registered
// Connect your MCP client to this serverNote: The server must be connected to stdio streams. For programmatic use, you need to set up stdin/stdout pipes.
Typical workflow for AI assistant adding a component:
Check Configuration
get_project_registriesnpx shadcn initSearch for Component
search_items_in_registriesView Component Details
view_items_in_registriesFind Usage Examples
get_item_examples_from_registriesGet Add Command
get_add_command_for_itemsnpx shadcn add @shadcn/buttonExecute Command
Verify Installation
get_audit_checklistError Handling in Workflow:
isError flag in responseMCP tools return structured errors:
// Zod validation error
{
content: [{
type: "text",
text: "Invalid input parameters:\n- registries: Required"
}],
isError: true
}
// Registry error
{
content: [{
type: "text",
text: "Error (REGISTRY_NOT_FOUND): Registry @custom not found\n\n💡 Check your components.json configuration"
}],
isError: true
}
// General error
{
content: [{
type: "text",
text: "Error: Failed to fetch registry items"
}],
isError: true
}Error Response Structure:
isError: true - Indicates error response (always check this first)content - Array with error message (always contains at least one text item)Common Error Codes:
REGISTRY_NOT_FOUND - Registry not configured or invalidCONFIG_MISSING - components.json not foundVALIDATION_ERROR - Invalid input parametersNETWORK_ERROR - Failed to fetch from registryNOT_FOUND - Item not found in registryUNAUTHORIZED - Authentication requiredFORBIDDEN - Access deniedPARSE_ERROR - Invalid response formatError Handling Best Practices:
isError flag before processing responseDebug and inspect MCP server with the MCP Inspector:
pnpm dlx @modelcontextprotocol/inspector node dist/index.js mcpThis launches an interactive inspector for testing MCP tools and viewing requests/responses.
Inspector Features:
MCP tools require components.json to be present:
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"tailwind": {
"css": "app/globals.css",
"baseColor": "slate"
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
},
"registries": {
"@shadcn": "https://ui.shadcn.com/r/{name}.json"
}
}If components.json is missing, tools will return appropriate error messages with instructions to run npx shadcn init.
Configuration Discovery:
AI assistants can integrate with the MCP server to provide intelligent component management:
The MCP protocol enables seamless interaction between AI assistants and the shadcn CLI ecosystem.
get_project_registries before other operations to verify setupisError flag and parse error messages for actionable suggestionslimit and offset parameters to manage response sizesearch_items_in_registries to find components, then view_items_in_registries for detailsget_item_examples_from_registries before implementingget_audit_checklist after adding components to ensure proper installation@ and item names include registry prefix${TOKEN})