Skip to main content
Glama
totodev999

shadcn-ui MCP Server

by totodev999

get_component_examples

Retrieve practical code examples for shadcn/ui components to implement UI elements correctly in your projects.

Instructions

Get usage examples for a specific shadcn/ui component

Input Schema

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

Implementation Reference

  • Main handler function for the get_component_examples tool. It validates the component name, fetches examples using fetchComponentExamples, and returns them in a standardized response format. Handles errors appropriately.
     * Handle the get_component_examples tool request
     */
    private async handleGetComponentExamples(args: any) {
      const componentName = this.validateComponentName(args);
    
      try {
        // Fetch component examples
        const examples = await this.fetchComponentExamples(componentName);
        return this.createSuccessResponse(examples);
      } catch (error) {
        this.handleAxiosError(error, `Component examples for "${componentName}"`);
      }
    }
  • Core helper function that orchestrates fetching examples by scraping the shadcn/ui docs page with cheerio, collecting code blocks, and fetching additional demo from GitHub.
    /**
     * Fetches component examples from documentation and GitHub
     * @param componentName Name of the component
     * @returns Array of component examples
     */
    private async fetchComponentExamples(
      componentName: string
    ): Promise<ComponentExample[]> {
      const response = await this.axiosInstance.get(
        `${this.SHADCN_DOCS_URL}/docs/components/${componentName}`
      );
      const $ = cheerio.load(response.data);
    
      const examples: ComponentExample[] = [];
    
      // Collect examples from different sources
      this.collectGeneralCodeExamples($, examples);
      this.collectSectionExamples($, 'Usage', 'Basic usage example', examples);
      this.collectSectionExamples($, 'Link', 'Link usage example', examples);
      await this.collectGitHubExamples(componentName, examples);
    
      return examples;
    }
  • Helper function to extract general code examples (pre blocks) from the documentation page, associating them with nearby headings for titles.
    /**
     * Collects general code examples from the page
     * @param $ Cheerio instance
     * @param examples Array to add examples to
     */
    private collectGeneralCodeExamples(
      $: cheerio.CheerioAPI,
      examples: ComponentExample[]
    ): void {
      const codeBlocks = $('pre');
      codeBlocks.each((i, el) => {
        const code = $(el).text().trim();
        if (code) {
          // Find heading before code block
          let title = 'Code Example ' + (i + 1);
          let description = 'Code example';
    
          // Look for headings
          let prevElement = $(el).prev();
          while (
            prevElement.length &&
            !prevElement.is('h1') &&
            !prevElement.is('h2') &&
            !prevElement.is('h3')
          ) {
            prevElement = prevElement.prev();
          }
    
          if (prevElement.is('h2') || prevElement.is('h3')) {
            title = prevElement.text().trim();
            description = `${title} example`;
          }
    
          examples.push({
            title,
            code,
            description,
          });
        }
      });
    }
  • Helper to fetch additional demo code example directly from the shadcn/ui GitHub repo raw file.
    private async collectGitHubExamples(
      componentName: string,
      examples: ComponentExample[]
    ): Promise<void> {
      try {
        const githubResponse = await this.axiosInstance.get(
          `${this.SHADCN_RAW_GITHUB_URL}/apps/www/registry/default/example/${componentName}-demo.tsx`
        );
    
        if (githubResponse.status === 200) {
          examples.push({
            title: 'GitHub Demo Example',
            code: githubResponse.data,
          });
        }
      } catch (error) {
        // Continue even if GitHub fetch fails
        console.error(
          `Failed to fetch GitHub example for ${componentName}:`,
          error
        );
      }
    }
  • src/index.ts:133-147 (registration)
    Tool registration in the list_tools response, including name, description, and input schema.
    {
      name: 'get_component_examples',
      description: 'Get usage examples for a specific shadcn/ui component',
      inputSchema: {
        type: 'object',
        properties: {
          componentName: {
            type: 'string',
            description:
              'Name of the shadcn/ui component (e.g., "accordion", "button")',
          },
        },
        required: ['componentName'],
      },
    },
  • Input schema definition for the tool, specifying the required 'componentName' parameter.
    inputSchema: {
      type: 'object',
      properties: {
        componentName: {
          type: 'string',
          description:
            'Name of the shadcn/ui component (e.g., "accordion", "button")',
        },
      },
      required: ['componentName'],
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves 'usage examples,' which implies a read-only operation, but does not address potential behavioral traits such as error handling, rate limits, authentication needs, or output format. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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, clear sentence: 'Get usage examples for a specific shadcn/ui component.' It is front-loaded with the core purpose, avoids redundancy, and is appropriately sized for a simple tool. Every word earns its place, making it highly concise and well-structured.

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?

Given the tool's low complexity (1 parameter, no output schema, no annotations), the description is minimally complete. It covers the basic purpose but lacks details on behavioral aspects, usage guidelines, and output expectations. Without annotations or an output schema, the description should do more to compensate, but it remains adequate for a simple read operation, albeit with clear gaps.

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 has 100% description coverage, with the parameter 'componentName' fully documented in the schema. The description adds minimal value beyond the schema by specifying 'shadcn/ui component,' but does not provide additional semantics like example formats or constraints. With high schema coverage, the baseline score of 3 is appropriate as the schema handles most of the parameter documentation.

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 tool's purpose: 'Get usage examples for a specific shadcn/ui component.' It specifies the verb ('Get') and resource ('usage examples'), and the component type ('shadcn/ui') provides context. However, it does not explicitly differentiate from sibling tools like 'get_component_details' (which might return metadata) or 'search_components' (which might list components), leaving some ambiguity in sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives. It does not mention sibling tools like 'get_component_details' or 'list_shadcn_components', nor does it specify prerequisites or exclusions. The context is implied (e.g., for learning how to use a component), but no explicit usage instructions are given.

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/totodev999/shadcn-ui-mcp-server_clone'

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