Skip to main content
Glama
freema

MCP Design System Extractor

get_component_html

Extract HTML from Storybook component stories to analyze structure and styling for design system adoption and refactoring.

Instructions

Extract HTML from a specific component story in Storybook. Requires a story ID (format: "component-name--story-name", e.g., "button--primary", "forms-input--default"). Use list_components or get_component_variants first to find valid story IDs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentIdYesThe story ID in format "component-name--story-name" (e.g., "button--primary", "forms-input--default"). Get this from list_components or get_component_variants.
includeStylesNoWhether to include extracted CSS styles in the response (useful for understanding component styling)

Implementation Reference

  • The async handler function that executes the tool: validates input, fetches HTML from Storybook component using StorybookClient with timeout protection, formats response including optional styles, and handles errors.
    export async function handleGetComponentHTML(input: any) {
      let validatedInput: any;
      try {
        validatedInput = validateGetComponentHTMLInput(input);
        const client = new StorybookClient();
    
        const timeout = getEnvironmentTimeout(OPERATION_TIMEOUTS.fetchComponentHTML);
    
        // Add timeout wrapper
        const timeoutPromise = new Promise((_, reject) => {
          setTimeout(() => {
            const timeoutError = createTimeoutError(
              'get component HTML',
              timeout,
              undefined,
              `component ${validatedInput.componentId}`
            );
            reject(new Error(timeoutError.message));
          }, timeout);
        });
    
        const componentHTML = (await Promise.race([
          client.fetchComponentHTML(validatedInput.componentId),
          timeoutPromise,
        ])) as ComponentHTML;
    
        const response = {
          storyId: componentHTML.storyId,
          html: componentHTML.html,
          classes: componentHTML.classes,
          ...(validatedInput.includeStyles && { styles: componentHTML.styles }),
        };
    
        return formatSuccessResponse(
          response,
          `Extracted HTML for component: ${validatedInput.componentId}`
        );
      } catch (error) {
        return handleErrorWithContext(error, 'get component HTML', {
          storyId: validatedInput?.componentId || 'unknown',
          resource: 'component HTML',
        });
      }
    }
  • The tool specification including name, description, and input schema defining parameters: componentId (required string), includeStyles (optional boolean). Used for tool listing and validation in MCP.
    export const getComponentHTMLTool: Tool = {
      name: 'get_component_html',
      description:
        'Extract HTML from a specific component story in Storybook. Requires a story ID (format: "component-name--story-name", e.g., "button--primary", "forms-input--default"). Use list_components or get_component_variants first to find valid story IDs.',
      inputSchema: {
        type: 'object',
        properties: {
          componentId: {
            type: 'string',
            description:
              'The story ID in format "component-name--story-name" (e.g., "button--primary", "forms-input--default"). Get this from list_components or get_component_variants.',
          },
          includeStyles: {
            type: 'boolean',
            description:
              'Whether to include extracted CSS styles in the response (useful for understanding component styling)',
          },
        },
        required: ['componentId'],
      },
    };
  • src/index.ts:15-24 (registration)
    Registers the 'get_component_html' tool name to its handler function in the Map used to dispatch CallToolRequests.
    const toolHandlers = new Map<string, (input: any) => Promise<any>>([
      ['list_components', tools.handleListComponents],
      ['get_component_html', tools.handleGetComponentHTML],
      ['get_component_variants', tools.handleGetComponentVariants],
      ['search_components', tools.handleSearchComponents],
      ['get_component_dependencies', tools.handleGetComponentDependencies],
      ['get_theme_info', tools.handleGetThemeInfo],
      ['get_component_by_purpose', tools.handleGetComponentByPurpose],
      ['get_external_css', tools.handleGetExternalCSS],
    ]);
  • src/index.ts:26-35 (registration)
    Adds getComponentHTMLTool to the array of all tools returned in ListTools response.
    const allTools = [
      tools.listComponentsTool,
      tools.getComponentHTMLTool,
      tools.getComponentVariantsTool,
      tools.searchComponentsTool,
      tools.getComponentDependenciesTool,
      tools.getThemeInfoTool,
      tools.getComponentByPurposeTool,
      tools.getExternalCSSTool,
    ];
  • Zod-based input validator for get_component_html tool, parsing and typing the input object.
    export function validateGetComponentHTMLInput(input: any): GetComponentHTMLInput {
      const parsed = GetComponentHTMLInputSchema.parse(input);
      const result: GetComponentHTMLInput = {
        componentId: parsed.componentId,
      };
      if (parsed.includeStyles !== undefined) {
        result.includeStyles = parsed.includeStyles;
      }
      return result;
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool extracts HTML and optionally includes CSS styles, which is useful context. However, it doesn't mention potential errors (e.g., invalid story IDs), performance aspects, or the response format, leaving some behavioral gaps for a tool with no annotation coverage.

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 front-loaded with the core purpose, followed by prerequisites and examples in two efficient sentences. Every sentence adds value—the first defines the tool, and the second provides critical usage guidance—with no wasted words.

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

Completeness4/5

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

Given no annotations and no output schema, the description does well by explaining the tool's purpose, parameters, and prerequisites. However, it lacks details on the return value (e.g., HTML structure) and error handling, which would be helpful for a tool with no structured output information.

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%, so the schema already documents both parameters thoroughly. The description adds minimal value beyond the schema by reinforcing the story ID format and suggesting sources for it, but doesn't provide additional syntax or usage details. This meets the baseline for high schema coverage.

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

Purpose5/5

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

The description clearly states the specific action ('Extract HTML') and resource ('from a specific component story in Storybook'), distinguishing it from siblings like list_components (which lists components) or get_component_variants (which shows variants). It provides concrete examples of story IDs, making the purpose unambiguous.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('Requires a story ID') and provides clear alternatives for obtaining valid IDs ('Use list_components or get_component_variants first to find valid story IDs'). This directly addresses when to use this tool versus its siblings, offering practical 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/freema/mcp-design-system-extractor'

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