Skip to main content
Glama
renjismzy

Smart Code Reviewer

by renjismzy

analyze_code_quality

Analyze code to detect potential issues and provide improvement suggestions for better quality and maintainability.

Instructions

分析代码质量,检测潜在问题和改进建议

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes要分析的代码内容
languageYes编程语言 (javascript, typescript, python, java, etc.)
filenameNo文件名(可选)

Implementation Reference

  • Core handler function that executes the analyze_code_quality tool logic: calculates LOC, detects issues using language-specific analyzers, computes metrics like complexity and maintainability index, and generates recommendations.
    export async function analyzeCodeQuality(
      code: string,
      language: string,
      filename?: string
    ): Promise<CodeAnalysisResult> {
      const issues: CodeIssue[] = [];
      const metrics: QualityMetrics = {
        linesOfCode: 0,
        complexity: 0,
        maintainabilityIndex: 0,
        duplicateLines: 0,
        testCoverage: 0
      };
    
      // 基础指标计算
      const lines = code.split('\n');
      metrics.linesOfCode = lines.filter(line => line.trim().length > 0).length;
    
      // 通用代码问题检测
      await detectCommonIssues(code, language, issues);
      
      // 语言特定分析
      switch (language.toLowerCase()) {
        case 'javascript':
        case 'typescript':
          await analyzeJavaScript(code, issues, metrics);
          break;
        case 'python':
          await analyzePython(code, issues, metrics);
          break;
        case 'java':
          await analyzeJava(code, issues, metrics);
          break;
        default:
          await analyzeGeneric(code, issues, metrics);
      }
    
      // 计算可维护性指数
      metrics.maintainabilityIndex = calculateMaintainabilityIndex(metrics, issues.length);
    
      return {
        filename: filename || 'unknown',
        language,
        metrics,
        issues,
        overallScore: calculateOverallScore(metrics, issues),
        recommendations: generateRecommendations(issues, metrics)
      };
    }
  • MCP input schema definition for the analyze_code_quality tool, specifying parameters: code (string, required), language (string, required), filename (string, optional).
      type: 'object',
      properties: {
        code: {
          type: 'string',
          description: '要分析的代码内容'
        },
        language: {
          type: 'string',
          description: '编程语言 (javascript, typescript, python, java, etc.)'
        },
        filename: {
          type: 'string',
          description: '文件名(可选)'
        }
      },
      required: ['code', 'language']
    }
  • src/index.ts:45-66 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema.
      name: 'analyze_code_quality',
      description: '分析代码质量,检测潜在问题和改进建议',
      inputSchema: {
        type: 'object',
        properties: {
          code: {
            type: 'string',
            description: '要分析的代码内容'
          },
          language: {
            type: 'string',
            description: '编程语言 (javascript, typescript, python, java, etc.)'
          },
          filename: {
            type: 'string',
            description: '文件名(可选)'
          }
        },
        required: ['code', 'language']
      }
    },
    {
  • src/index.ts:157-159 (registration)
    Dispatch registration in CallToolRequest handler switch statement.
    case 'analyze_code_quality':
      return await this.handleAnalyzeCodeQuality(args);
    case 'generate_documentation':
  • TypeScript type definitions for output structures: CodeAnalysisResult, QualityMetrics, CodeIssue used by the tool.
    export interface CodeAnalysisResult {
      filename: string;
      language: string;
      metrics: QualityMetrics;
      issues: CodeIssue[];
      overallScore: number;
      recommendations: string[];
    }
    
    export interface QualityMetrics {
      linesOfCode: number;
      complexity: number;
      maintainabilityIndex: number;
      duplicateLines: number;
      testCoverage: number;
    }
    
    export interface CodeIssue {
      type: 'style' | 'maintainability' | 'performance' | 'error-handling' | 'security';
      severity: 'error' | 'warning' | 'info';
      message: string;
      line: number;
      column: number;
      rule: string;
      suggestion?: string;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It mentions detecting problems and suggesting improvements, but lacks details on what types of problems (e.g., bugs, performance, style), the format of suggestions, whether analysis is static/dynamic, computational requirements, or error handling. For a tool with no annotation coverage, this is insufficient.

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 a single, efficient sentence in Chinese that directly states the tool's function. It's appropriately concise without unnecessary words, though it could be slightly more structured by separating problem detection from suggestion generation for clarity.

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 tool's complexity (code analysis with multiple potential outputs), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the analysis returns (e.g., issues list, scores, recommendations), how results are structured, or any limitations. This leaves significant gaps for an agent to use the tool effectively.

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 all three parameters thoroughly. The description adds no additional meaning about parameters beyond what's in the schema (e.g., no examples, constraints, or usage notes). Baseline 3 is appropriate when the schema does the heavy lifting.

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: '分析代码质量,检测潜在问题和改进建议' (analyze code quality, detect potential problems and improvement suggestions). It specifies the verb 'analyze' and resource 'code quality' with additional outcomes. However, it doesn't explicitly differentiate from siblings like 'detect_security_issues' or 'suggest_refactoring' which might overlap in scope.

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. With siblings like 'detect_security_issues' and 'suggest_refactoring' that might handle similar aspects of code analysis, there's no indication of scope boundaries, prerequisites, or comparative use cases. This leaves the agent guessing about tool selection.

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/renjismzy/mcp-code'

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