Skip to main content
Glama

getComponentList

Retrieve all components from Storybook to view available UI elements and their documentation.

Instructions

Get a list of all components from the configured Storybook

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary handler for the getComponentList MCP tool. Fetches Storybook JSON data and uses version-specific helpers to extract and return the list of available components.
    private async getComponentList() {
      try {
        const response = await fetch(this.storybookUrl);
        if (!response.ok) {
          throw new Error(
            `Failed to fetch Storybook data: ${response.statusText}`
          );
        }
    
        const data = (await response.json()) as StorybookDataV3 | StorybookDataV5;
    
        const components =
          data.v === 3 ? getComponentListV3(data) : getComponentListV5(data);
    
        return {
          content: [
            {
              type: "text",
              text: `Available components:\n${components.join("\n")}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(
          `Failed to get component list: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • src/server.ts:151-159 (registration)
    Registration of the getComponentList tool in the ListTools handler, including name, description, and empty input schema.
    {
      name: "getComponentList",
      description:
        "Get a list of all components from the configured Storybook",
      inputSchema: {
        type: "object",
        properties: {},
      },
    },
  • Zod schema definition for getComponentList input (empty object). Note: not used in handler.
    const GetComponentListSchema = z.object({});
  • Helper function that extracts unique component names from Storybook V3 data by parsing story 'kind' fields.
    export const getComponentList = (storybookData: StorybookData) => {
      if (!storybookData || storybookData.v !== 3 || !storybookData.stories) {
        return [];
      }
    
      const componentSet = new Set<string>();
      const stories = storybookData.stories;
    
      for (const key in stories) {
        if (Object.prototype.hasOwnProperty.call(stories, key)) {
          const story = stories[key];
          // filter out docs pages
          if (story.parameters && !story.parameters.docsOnly) {
            // get component path or name from 'kind' property
            const componentPath = story.kind.split("/");
            // usually the last part is the component name
            const componentName = componentPath[componentPath.length - 1];
            componentSet.add(componentName.trim());
          }
        }
      }
    
      // align with  v5
      return Array.from(componentSet).sort();
    };
  • Helper function that extracts component names from Storybook V5 data by filtering 'docs' type entries and using their 'title'.
    export const getComponentList = (data: StorybookData) => {
      if (!data || data.v !== 5 || !data.entries) {
        return [];
      }
    
      const entries = data.entries;
    
      // extract component names, filter only docs type entries
      const components = Object.values(entries)
        .filter((entry) => entry.type === "docs")
        .map((entry) => entry.title)
        .filter((title: string) => title)
        .sort();
    
      // remove duplicates
      const uniqueComponents = [...new Set(components)];
      return uniqueComponents;
    };
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/mcpland/storybook-mcp'

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