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"],
      },
    },
Behavior4/5

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

Annotations declare readOnlyHint=true, and the description adds value by specifying the output is 'demo code illustrating usage,' which is beyond the annotation's indication of 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?

Single concise sentence with no fluff, immediately conveying the tool's purpose.

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?

Adequately describes the purpose and return type (demo code). Could hint at format (e.g., JSX/TypeScript) but not necessary given low complexity and good schema coverage.

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 covers 100% of parameters with a description. The tool description does not add further semantics about the parameter beyond what is already in the schema.

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?

Clearly states the tool retrieves demo code for a shadcn/ui v4 component, distinguishing it from siblings like get_component (likely returns source) and get_component_metadata.

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?

Provides a clear use case (retrieving demo code), but lacks explicit guidance on when to use it versus alternatives, such as get_component or list_components.

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