List All Blocks
listBlocksRetrieves a complete list of Shadcn Space blocks, enabling agents to explore block types before deciding which ones to add or customize.
Instructions
Provides a complete list of all Shadcn Space blocks that can be used in a project. Agents can use this to explore available block types before deciding which ones to add or customize.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:24-56 (registration)Registration of the 'listBlocks' tool on the MCP server with input schema (empty object) and handler callback.
server.registerTool( "listBlocks", { title: "List All Blocks", description: "Provides a complete list of all Shadcn Space blocks that can be used in a project. Agents can use this to explore available block types before deciding which ones to add or customize.", inputSchema: z.object({}), }, async () => { try { const uiBlocks = await fetchUIBlocks(); return { content: [ { type: "text", text: JSON.stringify(uiBlocks, null, 2), }, ], }; } catch { return { content: [ { type: "text", text: "Failed to fetch MagicUI Blocks", }, ], isError: true, }; } }, ); - src/server.ts:32-55 (handler)Handler function for 'listBlocks' tool. Calls fetchUIBlocks() and returns the result as formatted JSON text, or an error message on failure.
async () => { try { const uiBlocks = await fetchUIBlocks(); return { content: [ { type: "text", text: JSON.stringify(uiBlocks, null, 2), }, ], }; } catch { return { content: [ { type: "text", text: "Failed to fetch MagicUI Blocks", }, ], isError: true, }; } }, - src/utils/api.ts:64-94 (helper)Helper function fetchUIBlocks() that fetches registry.json from shadcnspace.com, filters items with type 'registry:block', and parses them using ComponentSchema.
export async function fetchUIBlocks() { try { const response = await fetch( "https://shadcnspace.com/r/registry.json", ); if (!response.ok) { throw new Error( `Failed to Fetch Registry.json : ${response.statusText} (Status: ${response.status})`, ); } const data = await response.json(); return data.items .filter((item: any) => item.type === "registry:block") .map((item: any) => { try { return ComponentSchema.parse({ name: item.name, type: item.type, description: item.description, title: item.title, }); } catch (parseError) { return null; } }); } catch (error) { return []; } } - src/utils/api.ts:4-9 (schema)ComponentSchema used by fetchUIBlocks() to validate/parse block data (fields: name, title, type, description).
const ComponentSchema = z.object({ name: z.string(), title: z.string().optional(), // Only optional because of interactive-hover-button type: z.string(), description: z.string().optional(), // Only optional because of interactive-hover-button }); - dist/server.js:15-42 (registration)Compiled (dist) version of the 'listBlocks' tool registration, identical in behavior to src/server.ts.
server.registerTool("listBlocks", { title: "List All Blocks", description: "Provides a complete list of all Shadcn Space blocks that can be used in a project. Agents can use this to explore available block types before deciding which ones to add or customize.", inputSchema: z.object({}), }, async () => { try { const uiBlocks = await fetchUIBlocks(); return { content: [ { type: "text", text: JSON.stringify(uiBlocks, null, 2), }, ], }; } catch { return { content: [ { type: "text", text: "Failed to fetch MagicUI Blocks", }, ], isError: true, }; } });