Skip to main content
Glama
Jpisnice

@jpisnice/shadcn-ui-mcp-server

by Jpisnice

list_blocks

Read-only

Retrieve all shadcn/ui v4 blocks, grouped by category. Optionally filter by category such as calendar, dashboard, login, sidebar, or products.

Instructions

Get all available shadcn/ui v4 blocks with categorization

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryNoFilter by category (calendar, dashboard, login, sidebar, products)

Implementation Reference

  • The main handler function for the 'list_blocks' tool. It checks if the framework is react-native (returns empty), then calls axios.getAvailableBlocks(category) to fetch categorized blocks from the shadcn/ui GitHub repository.
    export async function handleListBlocks({ category }: { category?: string }) {
      const framework = getFramework();
    
      if (framework === "react-native") {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  categories: {},
                  totalBlocks: 0,
                  availableCategories: [],
                  message:
                    "Blocks are not available for React Native framework. The react-native-reusables repository does not provide block templates.",
                },
                null,
                2
              ),
            },
          ],
        };
      }
    
      try {
        const axios = await getAxiosImplementation();
        const blocks = await axios.getAvailableBlocks(category);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(blocks, null, 2),
            },
          ],
        };
      } catch (error) {
        logError("Failed to list blocks", error);
        throw new Error(
          `Failed to list blocks: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • The getAvailableBlocks function that actually fetches available blocks from the GitHub API. It lists the blocks directory, categorizes blocks (calendar, dashboard, login, sidebar, products, etc.), and optionally filters by category.
    async function getAvailableBlocks(category?: string): Promise<any> {
        const blocksPath = `${getRegistryBasePath()}/blocks`;
        
        try {
            const response = await githubApi.get(`/repos/${REPO_OWNER}/${REPO_NAME}/contents/${blocksPath}?ref=${REPO_BRANCH}`);
            
            if (!Array.isArray(response.data)) {
                throw new Error('Unexpected response from GitHub API');
            }
            
            const blocks: any = {
                calendar: [],
                dashboard: [],
                login: [],
                sidebar: [],
                products: [],
                authentication: [],
                charts: [],
                mail: [],
                music: [],
                other: []
            };
            
            for (const item of response.data) {
                const blockInfo: any = {
                    name: item.name.replace('.tsx', ''),
                    type: item.type === 'file' ? 'simple' : 'complex',
                    path: item.path,
                    size: item.size || 0,
                    lastModified: item.download_url ? 'Available' : 'Directory'
                };
                
                // Add description based on name patterns
                if (item.name.includes('calendar')) {
                    blockInfo.description = 'Calendar component for date selection and scheduling';
                    blocks.calendar.push(blockInfo);
                } else if (item.name.includes('dashboard')) {
                    blockInfo.description = 'Dashboard layout with charts, metrics, and data display';
                    blocks.dashboard.push(blockInfo);
                } else if (item.name.includes('login') || item.name.includes('signin')) {
                    blockInfo.description = 'Authentication and login interface';
                    blocks.login.push(blockInfo);
                } else if (item.name.includes('sidebar')) {
                    blockInfo.description = 'Navigation sidebar component';
                    blocks.sidebar.push(blockInfo);
                } else if (item.name.includes('products') || item.name.includes('ecommerce')) {
                    blockInfo.description = 'Product listing and e-commerce components';
                    blocks.products.push(blockInfo);
                } else if (item.name.includes('auth')) {
                    blockInfo.description = 'Authentication related components';
                    blocks.authentication.push(blockInfo);
                } else if (item.name.includes('chart') || item.name.includes('graph')) {
                    blockInfo.description = 'Data visualization and chart components';
                    blocks.charts.push(blockInfo);
                } else if (item.name.includes('mail') || item.name.includes('email')) {
                    blockInfo.description = 'Email and mail interface components';
                    blocks.mail.push(blockInfo);
                } else if (item.name.includes('music') || item.name.includes('player')) {
                    blockInfo.description = 'Music player and media components';
                    blocks.music.push(blockInfo);
                } else {
                    blockInfo.description = `${item.name} - Custom UI block`;
                    blocks.other.push(blockInfo);
                }
            }
            
            // Sort blocks within each category
            Object.keys(blocks).forEach(key => {
                blocks[key].sort((a: any, b: any) => a.name.localeCompare(b.name));
            });
            
            // Filter by category if specified
            if (category) {
                const categoryLower = category.toLowerCase();
                if (blocks[categoryLower]) {
                    return {
                        category,
                        blocks: blocks[categoryLower],
                        total: blocks[categoryLower].length,
                        description: `${category.charAt(0).toUpperCase() + category.slice(1)} blocks available in shadcn/ui v4`,
                        usage: `Use 'get_block' tool with the block name to get the full source code and implementation details.`
                    };
                } else {
                    return {
                        category,
                        blocks: [],
                        total: 0,
                        availableCategories: Object.keys(blocks).filter(key => blocks[key].length > 0),
                        suggestion: `Category '${category}' not found. Available categories: ${Object.keys(blocks).filter(key => blocks[key].length > 0).join(', ')}`
                    };
                }
            }
            
            // Calculate totals
            const totalBlocks = Object.values(blocks).flat().length;
            const nonEmptyCategories = Object.keys(blocks).filter(key => blocks[key].length > 0);
            
            return {
                categories: blocks,
                totalBlocks,
                availableCategories: nonEmptyCategories,
                summary: Object.keys(blocks).reduce((acc: any, key) => {
                    if (blocks[key].length > 0) {
                        acc[key] = blocks[key].length;
                    }
                    return acc;
                }, {}),
                usage: "Use 'get_block' tool with a specific block name to get full source code and implementation details.",
                examples: nonEmptyCategories.slice(0, 3).map(cat => 
                    blocks[cat][0] ? `${cat}: ${blocks[cat][0].name}` : ''
                ).filter(Boolean)
            };
            
        } catch (error: any) {
            if (error.response?.status === 404) {
                throw new Error('Blocks directory not found in the v4 registry');
            }
            throw error;
        }
    }
  • Input schema for the list_blocks tool, defining an optional 'category' string parameter to filter by block category.
    export const schema = {
      category: {
        type: "string",
        description:
          "Filter by category (calendar, dashboard, login, sidebar, products)",
      },
    };
  • Registration of the 'list_blocks' tool, mapping name, description, and inputSchema with the listBlocksSchema.
    'list_blocks': {
      name: 'list_blocks',
      description: 'Get all available shadcn/ui v4 blocks with categorization',
      inputSchema: {
        type: 'object',
        properties: listBlocksSchema
      }
    },
  • Mapping the handler function handleListBlocks to the tool name 'list_blocks' in the toolHandlers export object.
      list_blocks: handleListBlocks,
      apply_theme: handleApplyTheme,
      list_themes: handleListThemes,
      get_theme: handleGetTheme
    };
    
    export const toolSchemas = {
      get_component: getComponentSchema,
      get_component_demo: getComponentDemoSchema,
      list_components: listComponentsSchema,
      get_component_metadata: getComponentMetadataSchema,
      get_directory_structure: getDirectoryStructureSchema,
      get_block: getBlockSchema,
      list_blocks: listBlocksSchema,
      apply_theme: applyThemeSchema,
      list_themes: listThemesSchema,
      get_theme: getThemeSchema
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, so the agent knows this is a safe read. The description adds 'with categorization', hinting at output structure, but does not disclose response format, pagination, or other behavioral details. It does not contradict annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

One short sentence that communicates the core purpose and scope without any filler. Every word contributes meaning, and the structure is immediately scannable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple listing tool with one optional parameter, no output schema, and clear annotations, the description is nearly sufficient. It could mention what the returned list looks like or that it returns categorized data, but overall it is adequate for the low complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already provides 100% description coverage for the category parameter, including valid values. The description adds no further meaning beyond the schema, so it meets the baseline of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and the resource ('all available shadcn/ui v4 blocks'), and adds the scope 'with categorization'. It distinguishes from sibling tools like get_block (singular) and list_components (different resource type), though it does not explicitly name them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives. It does not mention when to prefer list_blocks over list_components or get_block, nor any exclusions. The only implied usage is that it lists blocks, which is already obvious from the name.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.