shadcn 4.21.4 → 4.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ import {Server}from'@modelcontextprotocol/sdk/server/index.js';import {ListToolsRequestSchema,CallToolRequestSchema}from'@modelcontextprotocol/sdk/types.js';import {searchRegistries,getRegistryItems}from'@shadcn/registry';import {withRegistryContext}from'@shadcn/registry/internal/registry/context';import {RegistryError}from'@shadcn/registry/internal/registry/errors';import {SEARCHABLE_TYPES,resolveSearchRegistries,findUnknownSearchTypes}from'@shadcn/registry/internal/registry/search';import c from'dedent';import {z as z$1}from'zod';import {getPackageRunner}from'@shadcn/registry/internal/get-package-manager';import {getRegistriesConfig}from'@shadcn/registry/internal/registry/api';var A="shadcn@latest";async function f(n){return `${await getPackageRunner(process.cwd())} ${A} ${n}`}async function d(n=process.cwd()){return {registries:(await getRegistriesConfig(n,{useCache:false})).registries}}async function h(n,t){let{query:r,registries:i}=t||{},o=await f("add"),a=n.items.map(g=>{let l=[`- ${g.name}`];return g.type&&l.push(`(${g.type})`),g.description&&l.push(`- ${g.description}`),g.registry&&l.push(`[${g.registry}]`),l.push(`
2
+ Add command: \`${o} ${g.addCommandArgument}\``),l.join(" ")}),s=`Found ${n.pagination.total} items`;r&&(s+=` matching "${r}"`),i&&i.length>0&&(s+=` in registries ${i.join(", ")}`),s+=":";let m=`Showing items ${n.pagination.offset+1}-${Math.min(n.pagination.offset+n.pagination.limit,n.pagination.total)} of ${n.pagination.total}:`,p=`${s}
3
+
4
+ ${m}
5
+
6
+ ${a.join(`
7
+
8
+ `)}`;return n.pagination.hasMore&&(p+=`
9
+
10
+ More items available. Use offset: ${n.pagination.offset+n.pagination.limit} to see the next page.`),p}function y(n){if(!n?.length)return null;let t=findUnknownSearchTypes(n);return t.length===0?null:`Unknown type${t.length===1?"":"s"}: ${t.join(", ")}. Valid types: ${SEARCHABLE_TYPES.join(", ")}.`}function x(n){if(!n.errors?.length)return "";let t=n.errors.map(r=>`- ${r.registry}: ${r.message}`);return `
11
+
12
+ Skipped ${n.errors.length} registr${n.errors.length===1?"y":"ies"} that failed to load:
13
+ ${t.join(`
14
+ `)}`}function j(n){return n.map(t=>[`## ${t.name}`,t.description?`
15
+ ${t.description}
16
+ `:"",t.type?`**Type:** ${t.type}`:"",t.files&&t.files.length>0?`**Files:** ${t.files.length} file(s)`:"",t.dependencies&&t.dependencies.length>0?`**Dependencies:** ${t.dependencies.join(", ")}`:"",t.devDependencies&&t.devDependencies.length>0?`**Dev Dependencies:** ${t.devDependencies.join(", ")}`:""].filter(Boolean).join(`
17
+ `))}function b(n,t){let r=n.map(o=>{let a=[`## Example: ${o.name}`,o.description?`
18
+ ${o.description}
19
+ `:""];return o.files?.length&&o.files.forEach(s=>{s.content&&(a.push(`### Code (${s.path}):
20
+ `),a.push("```tsx"),a.push(s.content),a.push("```"));}),a.filter(Boolean).join(`
21
+ `)});return `# Usage Examples
22
+
23
+ Found ${n.length} example${n.length>1?"s":""} matching "${t}":
24
+ `+r.join(`
25
+
26
+ ---
27
+
28
+ `)}var $=new Server({name:"shadcn",version:"1.0.0"},{capabilities:{logging:{},resources:{},tools:{}}});async function O(n){try{await $.sendLoggingMessage({level:"info",data:n});}catch{console.error(n);}}function u(n){return z$1.toJSONSchema(n,{target:"draft-7"})}$.setRequestHandler(ListToolsRequestSchema,async()=>({tools:[{name:"get_project_registries",description:"Get configured registry names from components.json - Returns error if no components.json exists (use init_project to create one)",inputSchema:u(z$1.object({}))},{name:"list_items_in_registries",description:"List items from registries (requires components.json - use init_project if missing)",inputSchema:u(z$1.object({registries:z$1.array(z$1.string()).optional().describe("Array of registry names to list (e.g., ['@shadcn', '@acme']). Omit to list from every registry configured in components.json."),types:z$1.array(z$1.string()).optional().describe(`Filter by item type. One of: ${SEARCHABLE_TYPES.join(", ")}.`),limit:z$1.number().optional().describe("Maximum number of items to return (defaults to 100; use 0 for no limit)"),offset:z$1.number().optional().describe("Number of items to skip for pagination")}))},{name:"search_items_in_registries",description:"Search for components in registries using fuzzy matching (requires components.json). After finding an item, use get_item_examples_from_registries to see usage examples.",inputSchema:u(z$1.object({registries:z$1.array(z$1.string()).optional().describe("Array of registry names to search (e.g., ['@shadcn', '@acme']). Omit to search every registry configured in components.json."),query:z$1.string().describe("Search query string for fuzzy matching against item names and descriptions"),types:z$1.array(z$1.string()).optional().describe(`Filter by item type. One of: ${SEARCHABLE_TYPES.join(", ")}.`),limit:z$1.number().optional().describe("Maximum number of items to return (defaults to 100; use 0 for no limit)"),offset:z$1.number().optional().describe("Number of items to skip for pagination")}))},{name:"view_items_in_registries",description:"View detailed information about specific registry items including the name, description, type and files content. For usage examples, use get_item_examples_from_registries instead.",inputSchema:u(z$1.object({items:z$1.array(z$1.string()).describe("Array of item names with registry prefix (e.g., ['@shadcn/button', '@shadcn/card'])")}))},{name:"get_item_examples_from_registries",description:"Find usage examples and demos with their complete code. Search for patterns like 'accordion-demo', 'button example', 'card-demo', etc. Returns full implementation code with dependencies.",inputSchema:u(z$1.object({registries:z$1.array(z$1.string()).optional().describe("Array of registry names to search (e.g., ['@shadcn', '@acme']). Omit to search every registry configured in components.json."),query:z$1.string().describe("Search query for examples (e.g., 'accordion-demo', 'button demo', 'card example', 'tooltip-demo', 'example-booking-form', 'example-hero'). Common patterns: '{item-name}-demo', '{item-name} example', 'example {item-name}'")}))},{name:"get_add_command_for_items",description:"Get the shadcn CLI add command for specific items in a registry. This is useful for adding one or more components to your project.",inputSchema:u(z$1.object({items:z$1.array(z$1.string()).describe("Array of items to get the add command for prefixed with the registry name (e.g., ['@shadcn/button', '@shadcn/card'])")}))},{name:"get_audit_checklist",description:"After creating new components or generating new code files, use this tool for a quick checklist to verify that everything is working as expected. Make sure to run the tool after all required steps have been completed.",inputSchema:u(z$1.object({}))}]}));$.setRequestHandler(CallToolRequestSchema,async n=>withRegistryContext(()=>z(n),{onGitHubAuthNotice:O}));async function z(n){try{if(!n.params.arguments)throw new Error("No tool arguments provided.");switch(n.params.name){case "get_project_registries":{let t=await d(process.cwd());return t?.registries?{content:[{type:"text",text:c`The following registries are configured in the current project:
29
+
30
+ ${Object.keys(t.registries).map(r=>`- ${r}`).join(`
31
+ `)}
32
+
33
+ You can view the items in a registry by running:
34
+ \`${await f("view @name-of-registry")}\`
35
+
36
+ For example: \`${await f("view @shadcn")}\` or \`${await f("view @shadcn @acme")}\` to view multiple registries.
37
+ `}]}:{content:[{type:"text",text:c`No components.json found or no registries configured.
38
+
39
+ To fix this:
40
+ 1. Use the \`init\` command to create a components.json file
41
+ 2. Or manually create components.json with a registries section`}]}}case "search_items_in_registries":{let r=z$1.object({registries:z$1.array(z$1.string()).optional(),query:z$1.string(),types:z$1.array(z$1.string()).optional(),limit:z$1.number().optional(),offset:z$1.number().optional()}).parse(n.params.arguments),i=y(r.types);if(i)return {content:[{type:"text",text:i}],isError:!0};let o=await d(process.cwd()),a=!r.registries?.length,s=resolveSearchRegistries(r.registries??[],o);if(s.length===0)return {content:[{type:"text",text:c`No registries are configured. Add registries to components.json (use get_project_registries to inspect) or pass them explicitly.`}]};let m=await searchRegistries(s,{query:r.query,types:r.types,limit:r.limit??100,offset:r.offset,config:o,useCache:!1,continueOnError:a}),p=x(m);return m.items.length===0?{content:[{type:"text",text:c`No items found matching "${r.query}" in registries ${s.join(", ")}, Try searching with a different query or registry.${p}`}]}:{content:[{type:"text",text:await h(m,{query:r.query,registries:s})+p}]}}case "list_items_in_registries":{let r=z$1.object({registries:z$1.array(z$1.string()).optional(),types:z$1.array(z$1.string()).optional(),limit:z$1.number().optional(),offset:z$1.number().optional(),cwd:z$1.string().optional()}).parse(n.params.arguments),i=y(r.types);if(i)return {content:[{type:"text",text:i}],isError:!0};let o=await d(process.cwd()),a=!r.registries?.length,s=resolveSearchRegistries(r.registries??[],o);if(s.length===0)return {content:[{type:"text",text:c`No registries are configured. Add registries to components.json (use get_project_registries to inspect) or pass them explicitly.`}]};let m=await searchRegistries(s,{types:r.types,limit:r.limit??100,offset:r.offset,config:o,useCache:!1,continueOnError:a}),p=x(m);return m.items.length===0?{content:[{type:"text",text:c`No items found in registries ${s.join(", ")}.${p}`}]}:{content:[{type:"text",text:await h(m,{registries:s})+p}]}}case "view_items_in_registries":{let r=z$1.object({items:z$1.array(z$1.string())}).parse(n.params.arguments),i=await getRegistryItems(r.items,{config:await d(process.cwd()),useCache:!1});if(i?.length===0)return {content:[{type:"text",text:c`No items found for: ${r.items.join(", ")}
42
+
43
+ Make sure the item names are correct and include the registry prefix (e.g., @shadcn/button).`}]};let o=j(i);return {content:[{type:"text",text:c`Item Details:
44
+
45
+ ${o.join(`
46
+
47
+ ---
48
+
49
+ `)}`}]}}case "get_item_examples_from_registries":{let r=z$1.object({query:z$1.string(),registries:z$1.array(z$1.string()).optional()}).parse(n.params.arguments),i=await d(),o=!r.registries?.length,a=resolveSearchRegistries(r.registries??[],i);if(a.length===0)return {content:[{type:"text",text:c`No registries are configured. Add registries to components.json (use get_project_registries to inspect) or pass them explicitly.`}]};let s=await searchRegistries(a,{query:r.query,config:i,useCache:!1,continueOnError:o});if(s.items.length===0)return {content:[{type:"text",text:c`No examples found for query "${r.query}".
50
+
51
+ Try searching with patterns like:
52
+ - "accordion-demo" for accordion examples
53
+ - "button demo" or "button example"
54
+ - Component name followed by "-demo" or "example"
55
+
56
+ You can also:
57
+ 1. Use search_items_in_registries to find all items matching your query
58
+ 2. View the main component with view_items_in_registries for inline usage documentation`}]};let m=s.items.map(g=>g.addCommandArgument),p=await getRegistryItems(m,{config:i,useCache:!1});return {content:[{type:"text",text:b(p,r.query)}]}}case "get_add_command_for_items":{let t=z$1.object({items:z$1.array(z$1.string())}).parse(n.params.arguments);return {content:[{type:"text",text:await f(`add ${t.items.join(" ")}`)}]}}case "get_audit_checklist":return {content:[{type:"text",text:c`## Component Audit Checklist
59
+
60
+ After adding or generating components, check the following common issues:
61
+
62
+ - [ ] Ensure imports are correct i.e named vs default imports
63
+ - [ ] If using next/image, ensure images.remotePatterns next.config.js is configured correctly.
64
+ - [ ] Ensure all dependencies are installed.
65
+ - [ ] Check for linting errors or warnings
66
+ - [ ] Check for TypeScript errors
67
+ - [ ] Use the Playwright MCP if available.
68
+ `}]};default:throw new Error(`Tool ${n.params.name} not found`)}}catch(t){if(t instanceof z$1.ZodError)return {content:[{type:"text",text:c`Invalid input parameters:
69
+ ${t.issues.map(i=>`- ${i.path.join(".")}: ${i.message}`).join(`
70
+ `)}
71
+ `}],isError:true};if(t instanceof RegistryError){let i=t.message;return t.suggestion&&(i+=`
72
+
73
+ \u{1F4A1} ${t.suggestion}`),t.context&&(i+=`
74
+
75
+ Context: ${JSON.stringify(t.context,null,2)}`),{content:[{type:"text",text:c`Error (${t.code}): ${i}`}],isError:true}}let r=t instanceof Error?t.message:String(t);return {content:[{type:"text",text:c`Error: ${r}`}],isError:true}}}export{$ as a};
package/dist/index.d.ts CHANGED
@@ -12,46 +12,9 @@ declare function getRegistryIcons(): Promise<Record<string, Record<string, strin
12
12
  * @deprecated This function is deprecated and will be removed in a future version.
13
13
  */
14
14
  declare function fetchTree(style: string, tree: z.infer<typeof registryIndexSchema>): Promise<({
15
- type: "registry:base";
16
15
  name: string;
16
+ type: "registry:base";
17
17
  $schema?: string | undefined;
18
- tailwind?: {
19
- config?: {
20
- theme?: Record<string, any> | undefined;
21
- content?: string[] | undefined;
22
- plugins?: string[] | undefined;
23
- } | undefined;
24
- } | undefined;
25
- config?: {
26
- menuColor?: "default" | "inverted" | "default-translucent" | "inverted-translucent" | undefined;
27
- menuAccent?: "subtle" | "bold" | undefined;
28
- iconLibrary?: string | undefined;
29
- style?: string | undefined;
30
- $schema?: string | undefined;
31
- rsc?: boolean | undefined;
32
- tsx?: boolean | undefined;
33
- tailwind?: {
34
- baseColor?: string | undefined;
35
- config?: string | undefined;
36
- css?: string | undefined;
37
- cssVariables?: boolean | undefined;
38
- prefix?: string | undefined;
39
- } | undefined;
40
- rtl?: boolean | undefined;
41
- aliases?: {
42
- components?: string | undefined;
43
- utils?: string | undefined;
44
- ui?: string | undefined;
45
- lib?: string | undefined;
46
- hooks?: string | undefined;
47
- } | undefined;
48
- registries?: Record<string, string | {
49
- url: string;
50
- params?: Record<string, string> | undefined;
51
- headers?: Record<string, string> | undefined;
52
- }> | undefined;
53
- } | undefined;
54
- css?: Record<string, any> | undefined;
55
18
  extends?: string | undefined;
56
19
  title?: string | undefined;
57
20
  author?: string | undefined;
@@ -61,25 +24,64 @@ declare function fetchTree(style: string, tree: z.infer<typeof registryIndexSche
61
24
  registryDependencies?: string[] | undefined;
62
25
  files?: ({
63
26
  path: string;
64
- type: "registry:page" | "registry:file";
27
+ type: "registry:file" | "registry:page";
65
28
  target: string;
66
29
  content?: string | undefined;
67
30
  } | {
68
31
  path: string;
69
- type: "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:theme" | "registry:style" | "registry:item" | "registry:base" | "registry:font" | "registry:example" | "registry:internal";
32
+ type: "registry:base" | "registry:font" | "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:theme" | "registry:style" | "registry:item" | "registry:example" | "registry:internal";
70
33
  content?: string | undefined;
71
34
  target?: string | undefined;
72
35
  })[] | undefined;
36
+ tailwind?: {
37
+ config?: {
38
+ content?: string[] | undefined;
39
+ theme?: Record<string, any> | undefined;
40
+ plugins?: string[] | undefined;
41
+ } | undefined;
42
+ } | undefined;
73
43
  cssVars?: {
74
44
  theme?: Record<string, string> | undefined;
75
45
  light?: Record<string, string> | undefined;
76
46
  dark?: Record<string, string> | undefined;
77
47
  } | undefined;
48
+ css?: Record<string, any> | undefined;
78
49
  envVars?: Record<string, string> | undefined;
79
50
  meta?: Record<string, any> | undefined;
80
51
  docs?: string | undefined;
81
52
  categories?: string[] | undefined;
53
+ config?: {
54
+ $schema?: string | undefined;
55
+ style?: string | undefined;
56
+ iconLibrary?: string | undefined;
57
+ rtl?: boolean | undefined;
58
+ menuColor?: "default" | "inverted" | "default-translucent" | "inverted-translucent" | undefined;
59
+ menuAccent?: "subtle" | "bold" | undefined;
60
+ registries?: Record<string, string | {
61
+ url: string;
62
+ params?: Record<string, string> | undefined;
63
+ headers?: Record<string, string> | undefined;
64
+ }> | undefined;
65
+ rsc?: boolean | undefined;
66
+ tsx?: boolean | undefined;
67
+ tailwind?: {
68
+ config?: string | undefined;
69
+ css?: string | undefined;
70
+ baseColor?: string | undefined;
71
+ prefix?: string | undefined;
72
+ cssVariables?: boolean | undefined;
73
+ } | undefined;
74
+ aliases?: {
75
+ components?: string | undefined;
76
+ utils?: string | undefined;
77
+ ui?: string | undefined;
78
+ lib?: string | undefined;
79
+ hooks?: string | undefined;
80
+ } | undefined;
81
+ } | undefined;
82
82
  } | {
83
+ name: string;
84
+ type: "registry:font";
83
85
  font: {
84
86
  family: string;
85
87
  provider: "google";
@@ -90,17 +92,7 @@ declare function fetchTree(style: string, tree: z.infer<typeof registryIndexSche
90
92
  selector?: string | undefined;
91
93
  dependency?: string | undefined;
92
94
  };
93
- type: "registry:font";
94
- name: string;
95
95
  $schema?: string | undefined;
96
- tailwind?: {
97
- config?: {
98
- theme?: Record<string, any> | undefined;
99
- content?: string[] | undefined;
100
- plugins?: string[] | undefined;
101
- } | undefined;
102
- } | undefined;
103
- css?: Record<string, any> | undefined;
104
96
  extends?: string | undefined;
105
97
  title?: string | undefined;
106
98
  author?: string | undefined;
@@ -110,36 +102,36 @@ declare function fetchTree(style: string, tree: z.infer<typeof registryIndexSche
110
102
  registryDependencies?: string[] | undefined;
111
103
  files?: ({
112
104
  path: string;
113
- type: "registry:page" | "registry:file";
105
+ type: "registry:file" | "registry:page";
114
106
  target: string;
115
107
  content?: string | undefined;
116
108
  } | {
117
109
  path: string;
118
- type: "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:theme" | "registry:style" | "registry:item" | "registry:base" | "registry:font" | "registry:example" | "registry:internal";
110
+ type: "registry:base" | "registry:font" | "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:theme" | "registry:style" | "registry:item" | "registry:example" | "registry:internal";
119
111
  content?: string | undefined;
120
112
  target?: string | undefined;
121
113
  })[] | undefined;
114
+ tailwind?: {
115
+ config?: {
116
+ content?: string[] | undefined;
117
+ theme?: Record<string, any> | undefined;
118
+ plugins?: string[] | undefined;
119
+ } | undefined;
120
+ } | undefined;
122
121
  cssVars?: {
123
122
  theme?: Record<string, string> | undefined;
124
123
  light?: Record<string, string> | undefined;
125
124
  dark?: Record<string, string> | undefined;
126
125
  } | undefined;
126
+ css?: Record<string, any> | undefined;
127
127
  envVars?: Record<string, string> | undefined;
128
128
  meta?: Record<string, any> | undefined;
129
129
  docs?: string | undefined;
130
130
  categories?: string[] | undefined;
131
131
  } | {
132
- type: "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:page" | "registry:file" | "registry:theme" | "registry:style" | "registry:item" | "registry:example" | "registry:internal";
133
132
  name: string;
133
+ type: "registry:file" | "registry:page" | "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:theme" | "registry:style" | "registry:item" | "registry:example" | "registry:internal";
134
134
  $schema?: string | undefined;
135
- tailwind?: {
136
- config?: {
137
- theme?: Record<string, any> | undefined;
138
- content?: string[] | undefined;
139
- plugins?: string[] | undefined;
140
- } | undefined;
141
- } | undefined;
142
- css?: Record<string, any> | undefined;
143
135
  extends?: string | undefined;
144
136
  title?: string | undefined;
145
137
  author?: string | undefined;
@@ -149,20 +141,28 @@ declare function fetchTree(style: string, tree: z.infer<typeof registryIndexSche
149
141
  registryDependencies?: string[] | undefined;
150
142
  files?: ({
151
143
  path: string;
152
- type: "registry:page" | "registry:file";
144
+ type: "registry:file" | "registry:page";
153
145
  target: string;
154
146
  content?: string | undefined;
155
147
  } | {
156
148
  path: string;
157
- type: "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:theme" | "registry:style" | "registry:item" | "registry:base" | "registry:font" | "registry:example" | "registry:internal";
149
+ type: "registry:base" | "registry:font" | "registry:lib" | "registry:block" | "registry:component" | "registry:ui" | "registry:hook" | "registry:theme" | "registry:style" | "registry:item" | "registry:example" | "registry:internal";
158
150
  content?: string | undefined;
159
151
  target?: string | undefined;
160
152
  })[] | undefined;
153
+ tailwind?: {
154
+ config?: {
155
+ content?: string[] | undefined;
156
+ theme?: Record<string, any> | undefined;
157
+ plugins?: string[] | undefined;
158
+ } | undefined;
159
+ } | undefined;
161
160
  cssVars?: {
162
161
  theme?: Record<string, string> | undefined;
163
162
  light?: Record<string, string> | undefined;
164
163
  dark?: Record<string, string> | undefined;
165
164
  } | undefined;
165
+ css?: Record<string, any> | undefined;
166
166
  envVars?: Record<string, string> | undefined;
167
167
  meta?: Record<string, any> | undefined;
168
168
  docs?: string | undefined;