search_components
Find shadcn/ui components by keyword to access relevant documentation and examples through a structured search query.
Instructions
Search for shadcn/ui components by keyword
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query to find relevant components |
Implementation Reference
- src/index.ts:581-595 (handler)Primary handler that validates the query, loads the components cache if necessary, calls the search helper, and formats the response.private async handleSearchComponents(args: any) { const query = this.validateSearchQuery(args); try { // Ensure components list is loaded await this.ensureComponentsListLoaded(); // Filter components matching the search query const results = this.searchComponentsByQuery(query); return this.createSuccessResponse(results); } catch (error) { this.handleAxiosError(error, "Search failed"); } }
- src/index.ts:145-154 (schema)Input schema definition for the search_components tool requiring a string 'query' parameter.inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query to find relevant components", }, }, required: ["query"], },
- src/index.ts:167-168 (registration)Switch case registration that routes search_components tool calls to the handler method.case "search_components": return await this.handleSearchComponents(request.params.arguments);
- src/index.ts:619-630 (helper)Helper function implementing the core search logic by filtering the cached components list based on query matching name or lowercase description.private searchComponentsByQuery(query: string): ComponentInfo[] { if (!this.componentsListCache) { return []; } return this.componentsListCache.filter(component => { return ( component.name.includes(query) || component.description.toLowerCase().includes(query) ); }); }
- src/index.ts:250-258 (helper)Helper function that validates the presence and type of the query argument and returns it lowercased.private validateSearchQuery(args: any): string { if (!args?.query || typeof args.query !== "string") { throw new McpError( ErrorCode.InvalidParams, "Search query is required and must be a string" ); } return args.query.toLowerCase(); }