Skip to main content
Glama
totodev999

shadcn-ui MCP Server

by totodev999

search_components

Find shadcn/ui components by keyword to access documentation and examples for building interfaces.

Instructions

Search for shadcn/ui components by keyword

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query to find relevant components

Implementation Reference

  • The main handler function for the search_components tool. It validates the query, ensures the components list is loaded, performs the search using a helper method, and returns the results.
    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:148-161 (registration)
    Registration of the search_components tool in the ListTools handler, defining name, description, and input schema.
    {
      name: 'search_components',
      description: 'Search for shadcn/ui components by keyword',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search query to find relevant components',
          },
        },
        required: ['query'],
      },
    },
  • JSON schema defining the input parameters for the search_components tool (query string required).
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: 'Search query to find relevant components',
        },
      },
      required: ['query'],
    },
  • Helper function implementing the core search logic by filtering cached components where name or description matches the query.
    private searchComponentsByQuery(query: string): ComponentInfo[] {
      if (!this.componentsListCache) {
        return [];
      }
    
      return this.componentsListCache.filter((component) => {
        return (
          component.name.includes(query) ||
          component.description.toLowerCase().includes(query)
        );
      });
    }
  • Helper function for input validation specific to the search_components tool query parameter.
    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();
    }

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