Skip to main content
Glama

storybook_get_stories

Retrieve all Storybook stories from a specified URL to support UI/UX development workflows and component management.

Instructions

Get list of all Storybook stories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlNoStorybook URL

Implementation Reference

  • Main handler function that fetches Storybook stories using axios/cheerio or stories.json endpoint, parses them, and returns formatted results.
    async getStories(args: any) {
      const params = StorybookStoriesSchema.parse(args);
      const url = params.url || this.storybookUrl;
    
      try {
        // Fetch the Storybook iframe.html to get stories data
        const response = await axios.get(`${url}/iframe.html`);
        const $ = cheerio.load(response.data);
        
        // Extract story data from the Storybook preview
        const stories: any[] = [];
        
        // Look for the stories configuration in the HTML
        $('script').each((_, element) => {
          const scriptContent = $(element).html();
          if (scriptContent && scriptContent.includes('__STORYBOOK_STORY_STORE__')) {
            // Parse the story store data
            const storyData = this.parseStoryData(scriptContent);
            stories.push(...storyData);
          }
        });
    
        // If no stories found in the HTML, try the stories.json endpoint
        if (stories.length === 0) {
          try {
            const storiesResponse = await axios.get(`${url}/stories.json`);
            const storiesData = storiesResponse.data;
            
            Object.entries(storiesData.stories || {}).forEach(([id, story]: [string, any]) => {
              stories.push({
                id,
                title: story.title,
                name: story.name,
                kind: story.kind,
                parameters: story.parameters
              });
            });
          } catch {
            // stories.json might not be available
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                url,
                storiesCount: stories.length,
                stories: stories.slice(0, 20), // Return first 20 stories
                message: stories.length > 0 
                  ? `Found ${stories.length} stories in Storybook`
                  : 'No stories found. Make sure Storybook is running and accessible.'
              }, null, 2)
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: `Error fetching Storybook stories: ${error.message}\nMake sure Storybook is running at ${url}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema for input validation of the storybook_get_stories tool (optional Storybook URL).
    const StorybookStoriesSchema = z.object({
      url: z.string().url().optional()
    });
  • src/index.ts:64-72 (registration)
    Tool registration including name, description, and input schema in the listTools response.
    {
      name: 'storybook_get_stories',
      description: 'Get list of all Storybook stories',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string', description: 'Storybook URL' }
        }
      }
  • src/index.ts:302-303 (registration)
    Switch case in CallToolRequest handler dispatching execution to the storybookTools.getStories method.
    case 'storybook_get_stories':
      return await this.storybookTools.getStories(args);
  • Helper method to parse story data from script content using regex.
    private parseStoryData(scriptContent: string): any[] {
      const stories: any[] = [];
      
      // Basic pattern matching to extract story information
      const storyRegex = /story\(['"]([^'"]+)['"]/g;
      let match;
      
      while ((match = storyRegex.exec(scriptContent)) !== null) {
        stories.push({
          name: match[1],
          extracted: true
        });
      }
      
      return stories;
    }
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 but only states the basic action. It doesn't cover critical aspects like whether this is a read-only operation, potential rate limits, authentication needs, error handling, or what the returned list structure looks like (e.g., format, pagination). This leaves significant gaps for a tool that fetches data.

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 a single, efficient sentence with zero wasted words, front-loading the core purpose ('Get list of all Storybook stories'). It achieves maximum clarity in minimal space, making it easy for an agent to parse quickly.

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 lack of annotations and output schema, the description is insufficiently complete. It doesn't explain the return format (e.g., JSON array, story metadata), error conditions, or behavioral nuances, leaving the agent under-informed for a data-fetching tool in a development context with multiple sibling tools.

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?

Schema description coverage is 100%, with the single parameter 'url' clearly documented in the schema. The description adds no additional parameter context beyond implying a Storybook URL is needed, so it meets the baseline for adequate but unenhanced parameter documentation.

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

Purpose4/5

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

The description clearly states the action ('Get list') and resource ('all Storybook stories'), making the tool's purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'storybook_test_component' or specify what constitutes a 'story' in Storybook context, preventing a perfect score.

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 alternatives like 'storybook_test_component' or other sibling tools. It lacks context about prerequisites (e.g., needing a running Storybook instance) or typical use cases, leaving the agent with minimal usage direction.

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/willem4130/ui-ux-mcp-server'

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