Skip to main content
Glama
code-alchemist01

Development Tools MCP Server

calculate_complexity

Analyze code cyclomatic complexity to measure structural complexity and identify potential maintenance issues in software files.

Instructions

Calculate cyclomatic complexity for code files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesYesFile paths to analyze

Implementation Reference

  • Handler for the 'calculate_complexity' tool. Parses input files, reads their contents using FileReader, computes complexity using ComplexityAnalyzer, and returns the result.
    case 'calculate_complexity': {
      const files = params.files as string[];
      const codeFiles = await FileReader.readFiles(files.join(','));
      const result = complexityAnalyzer.analyzeComplexity(codeFiles);
      return result;
    }
  • Registration of the 'calculate_complexity' tool in the codeQualityTools array, including name, description, and input schema.
    {
      name: 'calculate_complexity',
      description: 'Calculate cyclomatic complexity for code files',
      inputSchema: {
        type: 'object',
        properties: {
          files: {
            type: 'array',
            items: { type: 'string' },
            description: 'File paths to analyze',
          },
        },
        required: ['files'],
      },
    },
  • Input schema definition for the 'calculate_complexity' tool, specifying required 'files' array of strings.
    inputSchema: {
      type: 'object',
      properties: {
        files: {
          type: 'array',
          items: { type: 'string' },
          description: 'File paths to analyze',
        },
      },
      required: ['files'],
    },
  • Helper function analyzeComplexity in ComplexityAnalyzer class that computes complexity metrics (average, max, min, per-file) for multiple files by delegating to calculateCyclomaticComplexity.
    analyzeComplexity(files: CodeFile[]): {
      average: number;
      max: number;
      min: number;
      files: Array<{ path: string; complexity: number }>;
    } {
      if (files.length === 0) {
        return {
          average: 0,
          max: 0,
          min: 0,
          files: [],
        };
      }
    
      const complexities = files.map((file) => ({
        path: file.path,
        complexity: this.calculateCyclomaticComplexity(file.content),
      }));
    
      const values = complexities.map((c) => c.complexity);
      const average = values.reduce((sum, val) => sum + val, 0) / values.length;
      const max = Math.max(...values);
      const min = Math.min(...values);
    
      return {
        average: Math.round(average * 100) / 100,
        max,
        min,
        files: complexities,
      };
    }
  • Core helper function calculateComplexity that implements cyclomatic complexity calculation by counting matches of control flow keywords and operators in the code string.
    calculateComplexity(code: string): number {
      // Simple complexity calculation based on control flow statements
      const complexityKeywords = [
        /\bif\s*\(/g,
        /\belse\s*{/g,
        /\bfor\s*\(/g,
        /\bwhile\s*\(/g,
        /\bswitch\s*\(/g,
        /\bcase\s+/g,
        /\bcatch\s*\(/g,
        /\b&&/g,
        /\b\|\|/g,
        /\?\s*.*\s*:/g, // ternary operator
      ];
    
      let complexity = 1; // Base complexity
    
      for (const pattern of complexityKeywords) {
        const matches = code.match(pattern);
        if (matches) {
          complexity += matches.length;
        }
      }
    
      return complexity;
    }
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. It states what the tool does but doesn't describe how it behaves: no information about computational cost, output format, error handling, or whether it modifies files. For a tool that analyzes code, this leaves significant gaps in understanding its operational characteristics.

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 that communicates the core purpose without any wasted words. It's appropriately sized for a straightforward tool and is immediately understandable without requiring parsing of unnecessary details.

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?

For a tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the calculation returns (e.g., numerical scores, reports, or structured data), how results are formatted, or any behavioral aspects. Given the complexity of code analysis and lack of structured metadata, more context is needed for effective use.

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 schema description coverage is 100%, with the single parameter 'files' clearly documented as 'File paths to analyze'. The description adds no additional parameter information beyond what the schema provides, 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 verb ('calculate') and resource ('cyclomatic complexity for code files'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'analyze_code_quality' or 'generate_code_metrics' that might also provide complexity metrics, so it doesn't fully distinguish itself from alternatives.

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 'analyze_code_quality' or 'generate_code_metrics'. It doesn't mention prerequisites, exclusions, or specific contexts where this tool is preferred over other analysis tools in the server.

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/code-alchemist01/development-tools-mcp-Server'

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