Skip to main content
Glama
m-yoshiro

Storybook MCP Server

by m-yoshiro

list-components

Retrieve all available UI components from Storybook files to query and analyze design system elements.

Instructions

Returns all available components

Input Schema

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

Implementation Reference

  • The main handler function for the 'list-components' tool. It calls getComponents to fetch the list and returns it formatted as JSON text content.
    export const listComponents = async (storybookStaticDir: string) => {
      try {
        const components = await getComponents(storybookStaticDir);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(components, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error('Error listing components:', error);
        throw new McpError(ErrorCode.InternalError, 'Failed to list components');
      }
    };
  • Zod schema defining the optional 'path' input parameter for the list-components tool.
    const ListComponentsParamsSchema = z.object({
      path: z.string().optional().describe('Path to the index.json or stories.json file (optional if default path is provided)'),
    });
  • src/index.ts:54-57 (registration)
    Registration of the 'list-components' tool in the ListTools response, including name, description, and input schema.
      name: 'list-components',
      description: 'Returns all available components',
      inputSchema: zodToJsonSchema(ListComponentsParamsSchema.describe('Parameters for listing components')) as ToolInput,
    },
  • src/index.ts:82-83 (registration)
    Dispatch in the CallTool handler that invokes the listComponents function for the 'list-components' tool.
    case 'list-components':
      return listComponents(storybookStaticDir);
  • Core helper function that parses the Storybook stories.json file into a structured list of components with variants.
    export const getComponents = async (storybookStaticDir: string): Promise<Component[]> => {
      try {
        const storiesJsonContent = await fs.readFile(storybookStaticDir, 'utf-8');
    
        const storiesData: StorybookData = JSON.parse(storiesJsonContent);
        const components: Component[] = [];
        const storyEntries = storiesData.entries || storiesData.stories;
    
        for (const storyId in storyEntries) {
          const story = storyEntries[storyId];
    
          if (!story.id) {
            continue; // Skip stories without a title
          }
    
          // example-button--primary => example-button
          const componentId = story.id.split('--')[0];
          const componentName = componentId
            .replace(/-/g, '/')
            .replace(/(^|\/)(\w)/g, (_, separator, char) => `${separator}${char.toUpperCase()}`);
    
          // Check if the story already exists in the components array
          let component = components.find(c => c.name === story.title);
    
          if (!component) {
            component = {
              id: componentId,
              name: componentName,
              description: '',
              props: [],
              variants: {},
            };
            components.push(component);
          }
    
          if (component) {
            const storybookStaticDirname = path.dirname(storybookStaticDir);
            const storyFileFullPath = getAbsolutePath(path.resolve(storybookStaticDirname, '../', story.importPath || ''));
            const componentFullPath = getAbsolutePath(path.resolve(storybookStaticDirname, '../', story.componentPath || ''));
    
            component.variants[story.id] = {
              name: story.name,
              parameters: story.parameters,
              id: story.id,
              title: story.title,
              importPath: story.importPath,
              componentPath: story.componentPath,
              kind: story.kind,
              story: story.story,
              storyFileFullPath,
              componentFullPath,
            };
          }
        }
    
        return components;
      } catch (error) {
        console.error('Error reading or parsing stories.json:', error);
        return [];
      }
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Returns all available components' implies a read-only operation but doesn't specify whether this is a safe operation, what format the return takes, whether there are rate limits, or any error conditions. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just four words. It's front-loaded with the core purpose and contains no wasted words. While it may be under-specified, it's not verbose or poorly structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no annotations, no output schema, and a sibling tool exists, the description is incomplete. It doesn't explain what 'components' are, what 'available' means, how results are returned, or when to use this versus the sibling tool. For a tool that presumably returns data, the lack of output information is a significant gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already documents the single optional 'path' parameter. The description adds no parameter information beyond what the schema provides. According to the scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the basic purpose ('Returns all available components') which is clear but vague. It specifies the verb 'Returns' and resource 'components' but doesn't distinguish from the sibling tool 'find-components-by-name' or provide any scope details about what 'available' means. This is adequate but has clear gaps in differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus the sibling 'find-components-by-name' tool. There's no mention of alternatives, prerequisites, or context for usage. The agent would have to infer usage patterns from the tool names alone, which is insufficient guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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