Skip to main content
Glama
freema

MCP Design System Extractor

get_component_dependencies

Analyze rendered HTML to identify internal dependencies of a component, detecting React components, web components, and CSS class patterns for design system analysis.

Instructions

Analyze rendered HTML to find which other components a given component internally uses by detecting React components, web components, and CSS class patterns

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentIdYesThe story ID of the component (e.g., "example-button--primary")

Implementation Reference

  • The main handler function for the 'get_component_dependencies' tool. It validates the input, fetches the component's HTML from Storybook, analyzes it using regex patterns to detect nested components and CSS classes, categorizes dependencies as internal or external using heuristics, and returns a structured ComponentDependencies object.
    export async function handleGetComponentDependencies(input: any) {
      try {
        const validatedInput = validateGetComponentDependenciesInput(input);
        const client = new StorybookClient();
    
        // Fetch the component HTML
        const componentHTML = await client.fetchComponentHTML(validatedInput.componentId);
    
        // Analyze the HTML to find other components
        const dependencies = new Set<string>();
        const internalComponents = new Set<string>();
        const externalComponents = new Set<string>();
    
        // Common patterns for component detection
        const componentPatterns = [
          // React-style components: <Button>, <MuiButton>
          /<([A-Z][a-zA-Z0-9]*)\s*[^>]*>/g,
          // Web components: <my-button>, <app-header>
          /<([a-z]+-[a-z-]+)\s*[^>]*>/g,
          // Angular/Vue style: <app-button>, <v-btn>
          /<(app-[a-z-]+|v-[a-z-]+)\s*[^>]*>/g,
        ];
    
        // Extract component names from HTML
        for (const pattern of componentPatterns) {
          let match;
          while ((match = pattern.exec(componentHTML.html)) !== null) {
            const componentName = match[1];
            if (componentName && !isHTMLElement(componentName)) {
              dependencies.add(componentName);
            }
          }
        }
    
        // Also check for CSS classes that might indicate component usage
        const classPatterns = [
          /\b([A-Z][a-zA-Z0-9]+)-root\b/g,
          /\bMui([A-Z][a-zA-Z0-9]+)\b/g,
          /\bcomponent-([a-z-]+)\b/g,
        ];
    
        for (const pattern of classPatterns) {
          let match;
          while ((match = pattern.exec(componentHTML.html)) !== null) {
            const componentName = match[1];
            if (componentName) {
              dependencies.add(componentName);
            }
          }
        }
    
        // Try to categorize dependencies
        const allDependencies = Array.from(dependencies);
        for (const dep of allDependencies) {
          // Heuristic: if it starts with Mui, Material, Ant, etc., it's external
          if (/^(Mui|Material|Ant|Bootstrap|Semantic)/i.test(dep)) {
            externalComponents.add(dep);
          } else {
            internalComponents.add(dep);
          }
        }
    
        const componentDependencies: ComponentDependencies = {
          storyId: validatedInput.componentId,
          dependencies: allDependencies.sort(),
          internalComponents: Array.from(internalComponents).sort(),
          externalComponents: Array.from(externalComponents).sort(),
        };
    
        return formatSuccessResponse(
          componentDependencies,
          `Retrieved dependencies for component: ${validatedInput.componentId}`
        );
      } catch (error) {
        return handleError(error);
      }
    }
  • The Tool object definition including the name, description, and inputSchema for validation in MCP.
    export const getComponentDependenciesTool: Tool = {
      name: 'get_component_dependencies',
      description:
        'Analyze rendered HTML to find which other components a given component internally uses by detecting React components, web components, and CSS class patterns',
      inputSchema: {
        type: 'object',
        properties: {
          componentId: {
            type: 'string',
            description: 'The story ID of the component (e.g., "example-button--primary")',
          },
        },
        required: ['componentId'],
      },
    };
  • src/index.ts:15-24 (registration)
    Registration of the tool handler in the MCP server's toolHandlers Map, mapping 'get_component_dependencies' to its handleGetComponentDependencies function.
    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)
    Registration of the tool object in the allTools array, used for ListTools response.
    const allTools = [
      tools.listComponentsTool,
      tools.getComponentHTMLTool,
      tools.getComponentVariantsTool,
      tools.searchComponentsTool,
      tools.getComponentDependenciesTool,
      tools.getThemeInfoTool,
      tools.getComponentByPurposeTool,
      tools.getExternalCSSTool,
    ];
  • Helper function to filter out standard HTML elements from detected component tags.
    function isHTMLElement(tagName: string): boolean {
      const htmlElements = [
        'div',
        'span',
        'p',
        'a',
        'button',
        'input',
        'form',
        'label',
        'h1',
        'h2',
        'h3',
        'h4',
        'h5',
        'h6',
        'ul',
        'ol',
        'li',
        'table',
        'tr',
        'td',
        'th',
        'thead',
        'tbody',
        'tfoot',
        'img',
        'video',
        'audio',
        'canvas',
        'svg',
        'path',
        'g',
        'header',
        'footer',
        'nav',
        'main',
        'section',
        'article',
        'aside',
        'details',
        'summary',
        'figure',
        'figcaption',
      ];
    
      return htmlElements.includes(tagName.toLowerCase());
    }
Behavior2/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 mentions analyzing rendered HTML and detecting patterns, but does not disclose behavioral traits such as whether this is a read-only operation, performance implications, rate limits, or what happens if the componentId is invalid. It lacks details on output format or error handling, leaving gaps in transparency.

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, well-structured sentence that efficiently conveys the tool's purpose and scope without unnecessary words. It is front-loaded with the main action and includes specific details like detection targets, making it concise and effective.

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

Completeness3/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 simple input schema, the description is adequate for basic understanding but incomplete. It covers the purpose and parameter usage but lacks details on behavioral aspects, return values, or error cases, which are important for a tool performing analysis on rendered HTML.

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 input schema has 100% description coverage, with componentId documented as 'The story ID of the component (e.g., "example-button--primary")'. The description adds minimal value beyond this by implying the parameter is used for analysis, but does not provide additional syntax, format details, or constraints beyond what the schema already specifies.

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 tool's purpose with specific verbs ('analyze rendered HTML to find') and resources ('which other components a given component internally uses'), and distinguishes it from siblings by specifying detection of React components, web components, and CSS class patterns, which is not covered by other tools like get_component_html or list_components.

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

Usage Guidelines3/5

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

The description implies usage context by mentioning 'rendered HTML' and 'internally uses,' suggesting it's for dependency analysis, but it does not explicitly state when to use this tool versus alternatives like get_component_by_purpose or search_components, nor does it provide exclusions or prerequisites.

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