getUIBlocks
Retrieve a comprehensive list of all UI blocks from stackzero-labs, enabling integration and usage in applications via the MCP protocol.
Instructions
Provides a comprehensive list of all stackzero-labs/ui blocks.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:56-82 (registration)Registers the MCP tool 'getUIBlocks' with an inline handler that fetches UI blocks using fetchUIBlocks and returns them as JSON text.
server.tool( "getUIBlocks", "Provides a comprehensive list of all stackzero-labs/ui blocks.", {}, async () => { try { const uiBlocks = await fetchUIBlocks(); return { content: [ { type: "text", text: JSON.stringify(uiBlocks, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: "Failed to fetch stackzero-labs/ui blocks", }, ], }; } } ); - src/server.ts:60-81 (handler)Handler function for the getUIBlocks tool, which calls fetchUIBlocks and formats the response.
async () => { try { const uiBlocks = await fetchUIBlocks(); return { content: [ { type: "text", text: JSON.stringify(uiBlocks, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: "Failed to fetch stackzero-labs/ui blocks", }, ], }; } } - src/utils/api.ts:47-73 (helper)Core helper function that fetches the list of UI blocks from the registry, filters by type 'registry:block', parses with BlockSchema, and returns the array.
export async function fetchUIBlocks() { try { const response = await fetch(mcpConfig.registryFileUrl); if (!response.ok) { throw new Error( `Failed to fetch registry.json: ${response.statusText} - Status: ${response.status}` ); } const data = await response.json(); return data.registry .filter((item: any) => item.type === "registry:block") .map((item: any) => { try { return BlockSchema.parse({ name: item.name, type: item.type, description: item.description, }); } catch (parseError) { return null; } }); } catch (error) { return []; } } - src/utils/schemas.ts:10-14 (schema)Zod schema used to validate and parse individual UI block objects from the registry data.
export const BlockSchema = ComponentSchema.extend({ name: z.string(), type: z.string(), description: z.string().optional(), });