Skip to main content
Glama
Jpisnice

@jpisnice/shadcn-ui-mcp-server

by Jpisnice

get_component_demo

Read-only

Retrieve demo code showing how to use a specific shadcn/ui v4 component. Enter the component name to see its usage example.

Instructions

Get demo code illustrating how a shadcn/ui v4 component should be used

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentNameYesName of the shadcn/ui component (e.g., "accordion", "button")

Implementation Reference

  • The main handler function for the 'get_component_demo' tool. It uses the framework-specific axios implementation (determined by getAxiosImplementation) to fetch demo code for a given shadcn/ui component name, returning the code as text content.
    export async function handleGetComponentDemo({ componentName }: { componentName: string }) {
      try {
        const axios = await getAxiosImplementation();
        const demoCode = await axios.getComponentDemo(componentName);
        return {
          content: [{ type: "text", text: demoCode }]
        };
      } catch (error) {
        logError(`Failed to get demo for component "${componentName}"`, error);
        throw new Error(`Failed to get demo for component "${componentName}": ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Svelte framework implementation: fetches component demo from the registry at REGISTRY_PATH/examples/{componentName}-demo.svelte via GitHub raw API.
    async function getComponentDemo(componentName: string): Promise<string> {
        const demoPath = `${REGISTRY_PATH}/examples/${componentName.toLowerCase()}-demo.svelte`;
    
        try {
            const response = await githubRaw.get(`/${demoPath}`);
            return response.data;
        } catch (error) {
            throw new Error(`Demo for component "${componentName}" not found in v4 registry`);
        }
    }
  • Default framework implementation (shadcn/ui): fetches component demo from {basePath}/examples/{componentName}-{suffix}.tsx via GitHub raw API, using getRegistryBasePath() and getDemoSuffix() for framework config.
    async function getComponentDemo(componentName: string): Promise<string> {
        const basePath = getRegistryBasePath();
        const suffix = getDemoSuffix();
        const demoPath = `${basePath}/examples/${componentName.toLowerCase()}-${suffix}.tsx`;
        
        try {
            const response = await githubRaw.get(`/${demoPath}`);
            return response.data;
        } catch (error) {
            throw new Error(`Demo for component "${componentName}" not found in v4 registry`);
        }
    }
  • React Native framework implementation: returns a static message that demo is not available in the React Native registry.
    async function getComponentDemo(componentName: string): Promise<string> {
      // React Native registry typically doesn't have dedicated demo files per component
      // For now, return an informative message
      return `Demo for component "${componentName}" is not available in the React Native registry. Check the showcase app at apps/showcase for examples.`;
    }
  • Vue framework implementation: tries multiple file paths (DEMOS_PATH/{Name}Demo.vue, DEMOS_PATH/{Name}.vue) to fetch the component demo from the Vue registry.
    async function getComponentDemo(
      componentName: string,
      style: string = "new-york-v4"
    ): Promise<string> {
      const formattedComponentName = formatComponentNameToCapital(componentName)
      const demoPaths = [
        `${DEMOS_PATH}/${formattedComponentName}Demo.vue`,
        `${DEMOS_PATH}/${formattedComponentName}.vue`,
      ]
    
      for (const demoPath of demoPaths) {
        try {
          const response = await githubRaw.get(`/${demoPath}`)
          return response.data
        } catch (error) {
          continue
        }
      }
    
      throw new Error(
        `Demo for component "${formattedComponentName}" not found in Vue registry (v4)`
      )
    }
  • Input schema definition for the tool: requires 'componentName' as a string with description 'Name of the shadcn/ui component (e.g., accordion, button)'.
    export const schema = {
      componentName: {
        type: 'string',
        description: 'Name of the shadcn/ui component (e.g., "accordion", "button")'
      }
    }; 
  • Tool registration object: maps 'get_component_demo' to its name, description, inputSchema (with required componentName). Also exported in toolHandlers and toolSchemas maps on lines 22 and 35.
    'get_component_demo': {
      name: 'get_component_demo',
      description: 'Get demo code illustrating how a shadcn/ui v4 component should be used',
      inputSchema: {
        type: 'object',
        properties: getComponentDemoSchema,
        required: ['componentName']
      }
    },
  • Server handler registration: includes the tool definition with name, description, inputSchema, and annotations (title 'Get Component Demo', readOnlyHint true) in the server's tool list.
    {
      name: 'get_component_demo',
      description: 'Get demo code illustrating how a shadcn/ui v4 component should be used',
      inputSchema: {
        type: 'object',
        properties: {
          componentName: {
            type: 'string',
            description: 'Name of the shadcn/ui component (e.g., "accordion", "button")',
          },
        },
        required: ['componentName'],
      },
      annotations: {
        title: "Get Component Demo",
        readOnlyHint: true,
      },
    },
  • Capabilities registration: defines the tool in the server's capabilities with description and inputSchema.
    get_component_demo: {
      description:
        "Get demo code illustrating how a shadcn/ui v4 component should be used",
      inputSchema: {
        type: "object",
        properties: {
          componentName: {
            type: "string",
            description:
              'Name of the shadcn/ui component (e.g., "accordion", "button")',
          },
        },
        required: ["componentName"],
      },
    },

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.8/5.0
Behavior3/5

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

The description is consistent with the readOnlyHint annotation and adds useful version/scope context ('shadcn/ui v4'). However, it does not disclose return format, output size, or behavior details beyond what the annotation already signals about safety.

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, front-loaded sentence that conveys the tool's exact purpose. Every word earns its place, with no filler or redundant restatement of the tool name.

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 one-parameter read-only tool without an output schema, the description plus annotation provides adequate context: what it returns (demo code), for what (shadcn/ui v4), and safety (readOnlyHint). It could briefly mention the demo format or relationship to get_component, but the low complexity makes the description mostly sufficient.

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?

Schema description coverage is 100% for the single componentName parameter, so the schema already documents the expected input. The description adds no parameter-specific meaning beyond what the schema provides, warranting the baseline score.

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 uses a specific verb-object pair ('Get demo code') and names the target resource ('shadcn/ui v4 component'). It clearly separates this tool from siblings like get_component and get_component_metadata by emphasizing its purpose is showing usage examples rather than fetching the component itself.

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 intended usage is implied by 'demo code illustrating how a shadcn/ui v4 component should be used,' but no explicit guidance is given about when to choose this over get_component or get_component_metadata. Sibling tools exist, so some direct differentiation would strengthen this dimension.

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