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
    };
Behavior3/5

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

Annotations already provide readOnlyHint=true, indicating a safe read operation. The description 'Get all available' is consistent but adds no extra behavioral context such as rate limits, data freshness, or pagination. With annotations covering the safety profile, a score of 3 is appropriate.

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?

The description is a single, efficient sentence that is front-loaded with the core purpose. Every word earns its place, with no filler or redundancy.

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

Completeness3/5

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

The tool is simple with one optional parameter and no output schema. However, the description does not indicate what information is returned (e.g., block names, IDs) or how results are structured. While 'with categorization' hints at grouping, it lacks explicit detail about the return format, which is a minor gap given the context of rich sibling tools.

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 covers the single optional parameter 'category' with a list of possible values. The description does not add meaning beyond what the schema already provides. Since schema coverage is 100%, the baseline score of 3 applies.

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

Purpose5/5

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

The description clearly states the verb 'Get', the resource 'all available shadcn/ui v4 blocks', and adds the context 'with categorization'. This distinguishes it from sibling tools like 'get_block' which targets a single block, and 'list_components' which lists components instead of blocks.

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

Usage Guidelines3/5

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

The description implies usage for listing blocks but does not explicitly state when to prefer this tool over siblings like 'get_block' or 'list_components'. No exclusions or alternative guidance is provided, so the usage context is only implied.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Jpisnice/shadcn-ui-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server