Skip to main content
Glama
code-alchemist01

Development Tools MCP Server

detect_code_smells

Identify problematic patterns in code files to improve maintainability and reduce technical debt by analyzing complexity and other quality metrics.

Instructions

Detect code smells in code files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesYesFile paths to analyze
maxComplexityNoMaximum allowed complexity

Implementation Reference

  • Handler for the 'detect_code_smells' tool: parses input, reads code files, runs analysis via CodeAnalyzer, returns detected code smells.
    case 'detect_code_smells': {
      const files = params.files as string[];
      const codeFiles = await FileReader.readFiles(files.join(','));
      const options: CodeAnalysisOptions = {
        maxComplexity: params.maxComplexity as number,
        checkCodeSmells: true,
      };
      const metrics = await codeAnalyzer.analyzeCodeQuality(codeFiles, options);
      return metrics.codeSmells;
    }
  • Input schema validating files (required) and optional maxComplexity for the tool.
    inputSchema: {
      type: 'object',
      properties: {
        files: {
          type: 'array',
          items: { type: 'string' },
          description: 'File paths to analyze',
        },
        maxComplexity: {
          type: 'number',
          description: 'Maximum allowed complexity',
          default: 10,
        },
      },
      required: ['files'],
  • Tool definition and registration in codeQualityTools export array.
    {
      name: 'detect_code_smells',
      description: 'Detect code smells in code files',
      inputSchema: {
        type: 'object',
        properties: {
          files: {
            type: 'array',
            items: { type: 'string' },
            description: 'File paths to analyze',
          },
          maxComplexity: {
            type: 'number',
            description: 'Maximum allowed complexity',
            default: 10,
          },
        },
        required: ['files'],
      },
    },
  • src/server.ts:18-25 (registration)
    MCP server registration: codeQualityTools (including detect_code_smells) added to allTools for list tools capability.
    const allTools = [
      ...codeAnalysisTools,
      ...codeQualityTools,
      ...dependencyAnalysisTools,
      ...lintingTools,
      ...webScrapingTools,
      ...apiDiscoveryTools,
    ];
  • Core helper function implementing code smell detection logic: long methods/files, high complexity, deep nesting, magic numbers, and simple duplicate detection.
    private detectCodeSmells(files: CodeFile[], options?: CodeAnalysisOptions): CodeSmell[] {
      const smells: CodeSmell[] = [];
    
      for (const file of files) {
        const lines = file.content.split('\n');
    
        // Long method detection
        if (file.lines > 100) {
          smells.push({
            type: 'long_method',
            severity: file.lines > 200 ? 'high' : 'medium',
            location: file.path,
            description: `Method/file is too long (${file.lines} lines). Consider breaking it down.`,
            suggestion: 'Extract methods or split into multiple files.',
          });
        }
    
        // High complexity detection
        const complexity = this.calculateComplexity(file.content);
        if (complexity > (options?.maxComplexity || 10)) {
          smells.push({
            type: 'high_complexity',
            severity: complexity > 20 ? 'high' : 'medium',
            location: file.path,
            line: 1,
            description: `High cyclomatic complexity (${complexity}).`,
            suggestion: 'Refactor to reduce complexity by extracting methods.',
          });
        }
    
        // Deep nesting detection
        let maxNesting = 0;
        let currentNesting = 0;
        for (let i = 0; i < lines.length; i++) {
          const line = lines[i];
          const openBraces = (line.match(/{/g) || []).length;
          const closeBraces = (line.match(/}/g) || []).length;
          currentNesting += openBraces - closeBraces;
          maxNesting = Math.max(maxNesting, currentNesting);
        }
    
        if (maxNesting > 4) {
          smells.push({
            type: 'deep_nesting',
            severity: maxNesting > 6 ? 'high' : 'medium',
            location: file.path,
            description: `Deep nesting detected (${maxNesting} levels).`,
            suggestion: 'Extract nested code into separate functions.',
          });
        }
    
        // Magic numbers detection
        const magicNumberPattern = /\b\d{3,}\b/g;
        const magicNumbers = file.content.match(magicNumberPattern);
        if (magicNumbers && magicNumbers.length > 5) {
          smells.push({
            type: 'magic_numbers',
            severity: 'low',
            location: file.path,
            description: `Multiple magic numbers detected (${magicNumbers.length}).`,
            suggestion: 'Extract magic numbers into named constants.',
          });
        }
    
        // Duplicate code detection (simple)
        const duplicatePattern = /(.{20,})\1{2,}/g;
        if (duplicatePattern.test(file.content)) {
          smells.push({
            type: 'duplicate_code',
            severity: 'medium',
            location: file.path,
            description: 'Potential duplicate code detected.',
            suggestion: 'Extract common code into reusable functions.',
          });
        }
      }
    
      return smells;
    }
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 states the action ('detect') but doesn't explain what 'code smells' entail, how detection works, whether it's read-only or has side effects, or any performance or output details. This leaves significant gaps in understanding 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.

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and appropriately sized for its content, making it easy to parse quickly.

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 code analysis and lack of annotations or output schema, the description is incomplete. It doesn't cover what 'code smells' are, how results are returned, or behavioral traits like side effects or performance, which are crucial for effective tool use in this context.

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 ('files' and 'maxComplexity') with descriptions. The tool description adds no additional meaning or context beyond what's in the schema, such as explaining file formats or complexity thresholds, resulting in a baseline score.

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 tool's purpose with a specific verb ('detect') and resource ('code smells in code files'), making it understandable. However, it doesn't differentiate from sibling tools like 'analyze_code_quality' or 'find_duplicate_code', which might have overlapping functionality, so it's not fully distinguished.

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, such as 'analyze_code_quality' or 'find_duplicate_code', which are related siblings. There's no mention of prerequisites, exclusions, or specific contexts for its application, leaving the agent to infer usage.

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