Skip to main content
Glama
StudentOfJS

MCP Frontend Testing Server

analyzeCode

Analyze and evaluate JavaScript, TypeScript, JSX, and TSX code for quality and structure, enabling effective frontend testing and React component validation within the MCP Frontend Testing Server ecosystem.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
languageNojavascript

Implementation Reference

  • The async handler function that performs the core logic of the analyzeCode tool: analyzes the provided code using performCodeAnalysis and returns structured JSON analysis or an error response.
    async ({ code, language }) => {
      try {
        // Analyze code to determine what kind of tests would be appropriate
        const analysis = performCodeAnalysis(code, language);
        return {
          content: [{ 
            type: 'text', 
            text: JSON.stringify(analysis, null, 2),
          }],
        };
      } catch (error) {
        return {
          isError: true,
          content: [{ 
            type: 'text', 
            text: `Error analyzing code: ${String(error)}`,
          }],
        };
      }
    }
  • Zod schema defining the input parameters for the analyzeCode tool: 'code' (string) and 'language' (enum with default).
    { 
      code: z.string(),
      language: z.enum(['javascript', 'typescript', 'jsx', 'tsx']).default('javascript')
    },
  • The registerAnalyzerTool function that registers the 'analyzeCode' tool on the MCP server, including name, input schema, and handler.
    export function registerAnalyzerTool(server: McpServer): void {
      server.tool(
        'analyzeCode',
        { 
          code: z.string(),
          language: z.enum(['javascript', 'typescript', 'jsx', 'tsx']).default('javascript')
        },
        async ({ code, language }) => {
          try {
            // Analyze code to determine what kind of tests would be appropriate
            const analysis = performCodeAnalysis(code, language);
            return {
              content: [{ 
                type: 'text', 
                text: JSON.stringify(analysis, null, 2),
              }],
            };
          } catch (error) {
            return {
              isError: true,
              content: [{ 
                type: 'text', 
                text: `Error analyzing code: ${String(error)}`,
              }],
            };
          }
        }
      );
    }
  • Helper function performCodeAnalysis that statically analyzes the code to detect React components, hooks, events, async ops, and recommends test types/frameworks.
    // Helper function to analyze code
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    export function performCodeAnalysis(code: string, language: string): any {
      const analysisResult: any = {
        codeType: {},
        complexity: {},
        recommendations: {}
      };
    
      try {    
        // Determine if the code is a React component
        const isReactComponent = code.includes('import React') ||
                              code.includes('from "react"') ||
                              code.includes("from 'react'") ||
                              code.includes('extends Component') ||
                              code.includes('React.Component') ||
                              ((code.includes('export') && code.includes('return')) &&
                               (code.includes('JSX.') || code.includes('<div') || code.includes('<>')));
    
        // Check if it's a function or class
        const isClass = code.includes('class ') && code.includes('extends ');
        const isFunction = code.includes('function ') || code.includes('=>');
        
        // Check if it uses hooks
        const usesHooks = code.includes('useState') || 
                        code.includes('useEffect') || 
                        code.includes('useContext') ||
                        code.includes('useReducer') ||
                        code.includes('useCallback') ||
                        code.includes('useMemo');
        
        // Count imports to determine complexity
        const importMatches = code.match(/import .+ from .+/g);
        const imports = importMatches ? importMatches.length : 0;
        
        // Look for event handlers
        const hasEvents = code.includes('onClick') || 
                        code.includes('onChange') || 
                        code.includes('onSubmit') ||
                        code.includes('addEventListener');
        
        // Look for async operations
        const hasAsync = code.includes('async ') || 
                        code.includes('await ') || 
                        code.includes('Promise') ||
                        code.includes('.then(') ||
                        code.includes('fetch(');
        
        const recommendedTestTypes: string[] = [];
        if (isReactComponent) {
          recommendedTestTypes.push('component');
          if (hasEvents || hasAsync) {
            recommendedTestTypes.push('e2e');
          } else {
            recommendedTestTypes.push('unit');
          }
        } else {
          recommendedTestTypes.push('unit');
        }
      
        // Recommend testing frameworks
        const recommendedFrameworks: string[] = [];
        if (isReactComponent) {
          recommendedFrameworks.push('jest');
          if (hasEvents) {
            recommendedFrameworks.push('cypress');
          } else {
            recommendedFrameworks.push('jest');
          }
        } else {
          recommendedFrameworks.push('jest');
        }
    
        analysisResult.codeType = {
          isReactComponent,
          isClass,
          isFunction,
          usesHooks,
        };
        analysisResult.complexity = {
          imports,
          hasEvents,
          hasAsync
        };
        analysisResult.recommendations = {
          testTypes: recommendedTestTypes,
          frameworks: recommendedFrameworks,
          priority: hasAsync ? 'high' : 'medium'
        };
      } catch (error: any) {
        console.error(`Error during code analysis: ${error.message}`);
      }
      
      return analysisResult;
    }
  • src/server.ts:29-29 (registration)
    Top-level registration of the analyzer tool during MCP server creation in createServer function.
    registerAnalyzerTool(server);
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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

Related 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/StudentOfJS/mcp-frontend-testing'

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