UNPKG

shadcn

Version:

Add components to your apps.

37 lines (35 loc) 4.5 kB
import { S, Y, I } from './chunk-P4EM45ZN.js'; import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js'; import { z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; var p=new Server({name:"shadcn",version:"0.0.1"},{capabilities:{resources:{},tools:{}}});p.setRequestHandler(ListToolsRequestSchema,async()=>({tools:[{name:"init",description:"Initialize a new project using a registry style project structure.",inputSchema:zodToJsonSchema(z.object({}))},{name:"get_items",description:"List all the available items in the registry",inputSchema:zodToJsonSchema(z.object({}))},{name:"get_item",description:"Get an item from the registry",inputSchema:zodToJsonSchema(z.object({name:z.string().describe("The name of the item to get from the registry. This is required.")}))},{name:"add_item",description:"Add an item from the registry",inputSchema:zodToJsonSchema(z.object({name:z.string().describe("The name of the item to add to the registry. This is required.")}))}]}));p.setRequestHandler(CallToolRequestSchema,async r=>{try{if(!r.params.arguments)throw new Error("Arguments are required");let e=process.env.REGISTRY_URL;if(!e)throw new Error("REGISTRY_URL is not set");switch(r.params.name){case"init":{let t=await u(e),n=t.items.find(o=>o.type==="registry:style"),a="To initialize a new project, run the following command:\n ```bash\n npx shadcn@canary init\n ```\n - This will install all the dependencies and theme for the project.\n - If running the init command installs a rules i.e registry.mdc file, you should follow the instructions in the file to configure the project.\n ",l=t.items.find(o=>o.type==="registry:file"&&o.name==="rules");return l&&(a+=` You should also install the rules for the project. \`\`\`bash npx shadcn@canary add ${s(l.name,e)} \`\`\` `),n?{content:[{type:"text",text:`To initialize a new project using the ${n.name} style, run the following command: \`\`\`bash npx shadcn@canary init ${s(n.name,e)} \`\`\` `}]}:{content:[{type:"text",text:a}]}}case"get_items":{let t=await u(e);return t.items?{content:[{type:"text",text:`The following items are available in the registry: ${JSON.stringify(t.items.map(n=>`- ${n.name} (${n.type}): ${n.description}`),null,2)}. - To install and use an item in your project, you run the following command: \`\`\`bash npx shadcn@canary add ${s("NAME_OF_THE_ITEM",e)} \`\`\` - Example: npx shadcn@canary add ${s(t.items[0].name,e)} to install the ${t.items[0].name} item. - To install multiple registry.items, you can do the following: \`\`\`bash npx shadcn@canary add ${s("NAME_OF_THE_ITEM_1",e)} ${s("NAME_OF_THE_ITEM_2",e)} \`\`\` - Before using any item, you need to add it first. - Adding the items will install all dependencies for the item and format the code as per the project. - Example components should not be installed directly unless asked. These components should be used as a reference to build other components. `}]}:{content:[{type:"text",text:"No items found in the registry"}]}}case"get_item":{let t=z.string().parse(r.params.arguments.name);if(!t)throw new Error("Name is required");let n=s(t,e),a=await S(n,"");return {content:[{type:"text",text:JSON.stringify(a,null,2)}]}}case"add_item":{let t=z.string().parse(r.params.arguments.name);if(!t)throw new Error("Name is required");let n=s(t,e);return await S(n,"")?{content:[{type:"text",text:`To install the ${t} item, run the following command: \`\`\`bash npx shadcn@canary add ${n} \`\`\``}]}:{content:[{type:"text",text:`Item ${t} not found in the registry.`}]}}default:throw new Error(`Tool ${r.params.name} not found`)}}catch(e){throw e instanceof z.ZodError?new Error(`Invalid input: ${JSON.stringify(e.errors)}`):e}});async function u(r){let[e]=await Y([r],{useCache:!1});return I.parse(e)}function s(r,e){return `${e.replace(/\/registry\.json$/,"")}/${r}.json`} export { p as a }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-MLPJ4AFS.js.map