Skip to main content
Glama

component_analyze

Analyze UI components for performance, accessibility, best practices, and SEO compliance to identify optimization opportunities and ensure development standards.

Instructions

Analyze component for performance and accessibility

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
checksNo

Implementation Reference

  • Core execution logic for the 'component_analyze' tool. Parses input arguments using Zod schema, runs specified checks (performance, accessibility, best-practices, SEO), computes overall score, and returns structured results.
    async analyze(args: any) {
      const params = ComponentAnalyzeSchema.parse(args);
      const checks = params.checks || ['performance', 'accessibility', 'best-practices'];
      
      try {
        const results: any = {
          summary: {
            score: 0,
            issues: [],
            suggestions: []
          },
          checks: {}
        };
    
        if (checks.includes('performance')) {
          results.checks.performance = this.analyzePerformance(params.code);
        }
    
        if (checks.includes('accessibility')) {
          results.checks.accessibility = this.analyzeAccessibility(params.code);
        }
    
        if (checks.includes('best-practices')) {
          results.checks.bestPractices = this.analyzeBestPractices(params.code);
        }
    
        if (checks.includes('seo')) {
          results.checks.seo = this.analyzeSEO(params.code);
        }
    
        // Calculate overall score
        const scores = Object.values(results.checks).map((check: any) => check.score);
        results.summary.score = scores.reduce((a, b) => a + b, 0) / scores.length;
        
        // Collect all issues and suggestions
        Object.values(results.checks).forEach((check: any) => {
          results.summary.issues.push(...(check.issues || []));
          results.summary.suggestions.push(...(check.suggestions || []));
        });
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(results, null, 2)
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: `Error analyzing component: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input structure for the component_analyze tool: required 'code' string and optional array of checks.
    const ComponentAnalyzeSchema = z.object({
      code: z.string(),
      checks: z.array(z.enum(['performance', 'accessibility', 'best-practices', 'seo'])).optional()
    });
  • src/index.ts:237-254 (registration)
    Tool registration in the listTools handler, defining name, description, and inputSchema matching the Zod schema.
    {
      name: 'component_analyze',
      description: 'Analyze component for performance and accessibility',
      inputSchema: {
        type: 'object',
        properties: {
          code: { type: 'string' },
          checks: {
            type: 'array',
            items: {
              type: 'string',
              enum: ['performance', 'accessibility', 'best-practices', 'seo']
            }
          }
        },
        required: ['code']
      }
    },
  • src/index.ts:328-329 (registration)
    Dispatch case in the callToolRequest handler that routes execution to ComponentTools.analyze method.
    case 'component_analyze':
      return await this.componentTools.analyze(args);
  • Helper method for performance analysis used by the handler, detecting common issues like missing optimizations and event listener leaks.
    private analyzePerformance(code: string): any {
      const issues = [];
      const suggestions = [];
      
      // Check for common performance issues
      if (code.includes('componentDidUpdate') && !code.includes('shouldComponentUpdate')) {
        issues.push('Missing shouldComponentUpdate optimization');
      }
      
      if (code.match(/useState.*map/)) {
        suggestions.push('Consider using useMemo for expensive computations');
      }
      
      if (code.includes('addEventListener') && !code.includes('removeEventListener')) {
        issues.push('Event listener not cleaned up');
      }
    
      return {
        score: Math.max(100 - issues.length * 20, 0),
        issues,
        suggestions,
        metrics: {
          renderComplexity: 'Low',
          reRenderRisk: issues.length > 0 ? 'High' : 'Low',
          memoryLeakRisk: code.includes('addEventListener') ? 'Medium' : 'Low'
        }
      };
    }
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 of behavioral disclosure. It mentions analyzing for performance and accessibility but doesn't describe how the analysis is performed, what the output looks like, any side effects, rate limits, or authentication needs. This leaves significant gaps for an agent to understand the tool's behavior.

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

Conciseness4/5

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

The description is concise with a single sentence that directly states the tool's function. It is front-loaded and wastes no words, though it could benefit from more detail to improve clarity and completeness.

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 complexity of analysis tools, lack of annotations, no output schema, and low schema coverage, the description is incomplete. It doesn't cover return values, error handling, or detailed usage scenarios, making it inadequate for an agent to fully understand the tool's context and application.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It doesn't explain the 'code' parameter (e.g., what format or language) or the 'checks' parameter (e.g., what each enum value means or how they affect analysis). This fails to add meaningful semantics beyond the basic schema.

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 tool analyzes components for performance and accessibility, which provides a general purpose but lacks specificity about what 'analyze' entails (e.g., static analysis, runtime profiling, or compliance checking). It distinguishes from siblings like 'component_create' but not clearly from other analysis tools like 'playwright_test_ui' or 'storybook_test_component'.

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description implies usage for analyzing components, but it doesn't specify prerequisites, contexts, or exclusions, such as when to choose this over 'playwright_test_ui' for UI testing or 'storybook_test_component' for component testing.

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