get_component_details
Retrieve comprehensive details about a specific shadcn/ui component, including usage examples and documentation, to streamline development workflows.
Instructions
Get detailed information about a specific shadcn/ui component
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| componentName | Yes | Name of the shadcn/ui component (e.g., "accordion", "button") |
Implementation Reference
- src/index.ts:302-321 (handler)The primary handler function for the 'get_component_details' tool. It validates the input component name, checks the cache, fetches details if necessary using fetchComponentDetails, caches the result, and returns a formatted JSON response.private async handleGetComponentDetails(args: any) { const componentName = this.validateComponentName(args); try { // Check cache first if (this.componentCache.has(componentName)) { return this.createSuccessResponse(this.componentCache.get(componentName)); } // Fetch component details const componentInfo = await this.fetchComponentDetails(componentName); // Save to cache this.componentCache.set(componentName, componentInfo); return this.createSuccessResponse(componentInfo); } catch (error) { this.handleAxiosError(error, `Component "${componentName}"`); } }
- src/index.ts:328-359 (helper)Key helper function that performs the actual web scraping and data extraction for component details from shadcn/ui documentation using axios and cheerio.private async fetchComponentDetails(componentName: string): Promise<ComponentInfo> { const response = await this.axiosInstance.get(`${this.SHADCN_DOCS_URL}/docs/components/${componentName}`); const $ = cheerio.load(response.data); // Extract component information const title = $("h1").first().text().trim(); // Extract description properly const description = this.extractDescription($); // Extract GitHub source code link const sourceUrl = `${this.SHADCN_GITHUB_URL}/tree/main/apps/www/registry/default/ui/${componentName}`; // Extract installation instructions const installation = this.extractInstallation($); // Extract usage examples const usage = this.extractUsage($); // Extract variant information const props = this.extractVariants($, componentName); return { name: componentName, description, url: `${this.SHADCN_DOCS_URL}/docs/components/${componentName}`, sourceUrl, installation: installation.trim(), usage: usage.trim(), props: Object.keys(props).length > 0 ? props : undefined, }; }
- src/index.ts:114-127 (registration)Tool registration entry in the ListToolsRequestSchema response, defining the tool name, description, and input schema.{ name: "get_component_details", description: "Get detailed information about 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"], }, },
- src/index.ts:163-164 (registration)Dispatcher case in the CallToolRequestSchema handler that routes calls to the specific tool handler.case "get_component_details": return await this.handleGetComponentDetails(request.params.arguments);
- src/index.ts:117-126 (schema)Input schema definition for the get_component_details 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"], },