Skip to main content
Glama
ymadd

shadcn-ui MCP Server

by ymadd

get_component_examples

Retrieve practical usage examples for shadcn/ui components to understand implementation patterns and accelerate development.

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

  • src/index.ts:128-141 (registration)
    Registration of the 'get_component_examples' tool in the ListToolsRequestSchema handler, including name, description, and input schema requiring 'componentName'.
    {
      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"],
      },
    },
  • The main handler function for the 'get_component_examples' tool. Validates the component name, fetches examples using helper methods, formats the response, and handles errors.
    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}"`);
      }
    }
  • src/index.ts:165-166 (registration)
    Dispatch/registration in the switch statement of the CallToolRequestSchema handler that routes calls to the tool handler.
    case "get_component_examples":
      return await this.handleGetComponentExamples(request.params.arguments);
  • Core helper function that implements the logic to scrape examples from shadcn/ui docs and GitHub for the given component.
    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;
    }
  • TypeScript interface defining the structure of component examples returned by the tool.
     * Interface for component example
     */
    interface ComponentExample {
      title: string;
      code: string;
      description?: string;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves examples but does not describe any behavioral traits such as rate limits, authentication needs, error handling, or the format of returned examples. This leaves significant gaps in understanding how the tool operates beyond its basic purpose.

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 directly states the tool's purpose without any unnecessary words. It is front-loaded and appropriately sized for a simple tool, making it easy for an agent to parse and understand quickly.

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 (one parameter, no output schema, no annotations), the description is adequate but incomplete. It covers the basic purpose but lacks details on behavioral aspects and usage guidelines, which are important for effective tool invocation. Without annotations or output schema, more context in the description would be beneficial.

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 schema description coverage is 100%, with the parameter 'componentName' clearly documented in the input schema. The description adds minimal value beyond this, as it only reiterates the need for a component name without providing additional context like valid examples or constraints. This meets the baseline for high schema coverage.

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 with a specific verb ('Get') and resource ('usage examples for a specific shadcn/ui component'), making it immediately understandable. However, it does not explicitly differentiate from sibling tools like 'get_component_details' or 'search_components', which might also provide example-related information, so it falls short of a perfect score.

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 like 'get_component_details' or 'search_components'. It implies usage for retrieving examples but offers no context on prerequisites, exclusions, or specific scenarios, leaving the agent to infer usage based on the tool name alone.

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/ymadd/shadcn-ui-mcp-server'

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