Skip to main content
Glama
m-yoshiro

Storybook MCP Server

by m-yoshiro

find-components-by-name

Search UI components by name or keyword in Storybook to locate specific elements and retrieve usage examples for development.

Instructions

Search components by name/keyword

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesComponent name or keyword to search for
pathNoPath to the index.json or stories.json file (optional if default path is provided)

Implementation Reference

  • Main handler function that fetches components from Storybook static dir, filters by name keyword (case-insensitive), and returns JSON stringified matching components as text content.
    export const findComponentsByName = async (
      args: z.infer<typeof FindComponentByNameParamsSchema> & { storybookStaticDir: string }
    ) => {
      try {
        const components = await getComponents(args.storybookStaticDir);
        const searchTerm = args.name.toLowerCase();
        const matchingComponents = components.filter((component: Component) =>
          component.name.toLowerCase().includes(searchTerm)
        );
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(matchingComponents, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error('Error finding component by name:', error);
        throw new McpError(ErrorCode.InternalError, 'Failed to find component by name');
      }
    };
  • src/index.ts:84-85 (registration)
    Switch case in CallToolRequestHandler that invokes the findComponentsByName handler with arguments.
    case 'find-components-by-name':
      return findComponentsByName({ name: args.name || '', storybookStaticDir });
  • src/index.ts:58-62 (registration)
    Tool registration in ListToolsResponse, defining name, description, and inputSchema.
    {
      name: 'find-components-by-name',
      description: 'Search components by name/keyword',
      inputSchema: zodToJsonSchema(findComponentsByNameParamsSchema.describe('Parameters for finding component by name')) as ToolInput,
    },
  • Zod schema for input parameters used in tool registration (name required, path optional).
    const findComponentsByNameParamsSchema = z.object({
      name: z.string().describe('Component name or keyword to search for'),
      path: z.string().optional().describe('Path to the index.json or stories.json file (optional if default path is provided)'),
    });
  • Local Zod schema for typing handler arguments (name only).
    const FindComponentByNameParamsSchema = z.object({
      name: z.string().describe('Component name or keyword to search for'),
    });
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/m-yoshiro/storybook-mcp'

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