Get Block Installation Command
getBlockInstallReturns the official installation command for a Shadcn Space block, enabling automatic addition to your project before customization.
Instructions
Returns the official installation command for a specific Shadcn Space block. Agents can use this to add a block to the project automatically before customizing it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The exact name of the block, e.g., 'hero-01'. |
Implementation Reference
- src/server.ts:106-153 (handler)The handler function for the 'getBlockInstall' tool. It takes a block name, fetches component details via fetchComponentDetails, and returns the installation command 'npx shadcn@latest add @shadcn-space/<name>'.
async ({ name }) => { try { const componentDetails = await fetchComponentDetails(name); process.stderr.write(`Fetched ${componentDetails} blocks\n`); if (!componentDetails || !componentDetails.files?.length) { return { content: [ { type: "text", text: `Component "${name}" not found.`, }, ], isError: true, }; } const installCommand = `npx shadcn@latest add @shadcn-space/${name}`; return { content: [ { type: "text", text: `Block "${name}" found. AGENT RULE: You MUST install this component using the command below. You are NOT allowed to recreate, rewrite, or approximate this component. Install command: ${installCommand} `, }, ], }; } catch { return { content: [ { type: "text", text: `Failed to fetch component "${name}"`, }, ], isError: true, }; } }, ); - src/server.ts:96-105 (schema)The input schema for the 'getBlockInstall' tool. It defines a required string input 'name' describing the block name (e.g., 'hero-01').
{ title: "Get Block Installation Command", description: "Returns the official installation command for a specific Shadcn Space block. Agents can use this to add a block to the project automatically before customizing it.", inputSchema: z.object({ name: z .string() .describe("The exact name of the block, e.g., 'hero-01'."), }), }, - src/server.ts:93-95 (registration)Registration of the 'getBlockInstall' tool on the MCP server using server.registerTool().
// Register tools for adding a Block server.registerTool( "getBlockInstall", - src/utils/api.ts:97-120 (helper)Helper function fetchComponentDetails that fetches component details from the registry JSON at shadcnspace.com and finds the component by name.
export async function fetchComponentDetails(name: string) { try { const response = await fetch( `https://shadcnspace.com/r/registry.json`, ); if (!response.ok) { throw new Error( `Failed to fetch component ${name}: ${response.statusText}`, ); } const data = await response.json(); const component = data.items.find((item: any) => { return item.name === name; }); return component; } catch (error) { console.error(`Error fetching component ${name}:`, error); throw error; } }