Skip to main content
Glama
ymadd
by ymadd

get_component_examples

Retrieve practical usage examples for shadcn/ui components by specifying the component name, enabling efficient integration into UI development workflows.

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 response. Includes the tool name, description, and input schema defining the required 'componentName' parameter.
    { 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"], }, },
  • Main handler function for executing the 'get_component_examples' tool. Validates input, fetches examples using helper function, handles errors, and returns formatted response.
    * 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}"`); } }
  • src/index.ts:165-166 (registration)
    Tool dispatch/registration in the CallToolRequestSchema switch statement, routing calls to the specific handler.
    case "get_component_examples": return await this.handleGetComponentExamples(request.params.arguments);
  • Core helper function that fetches and collects component examples from documentation pages and GitHub source.
    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 ComponentExample { title: string; code: string; description?: string; }

Other Tools

Related 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