Skip to main content
Glama
JJJHoons

Python Code Review MCP Agent

by JJJHoons

compare_code_versions

Identify improvements or regressions in Python code quality and security by comparing two versions to track changes effectively.

Instructions

Compare two versions of Python code to identify improvements or regressions in quality and security.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originalCodeYesOriginal version of the Python code
revisedCodeYesRevised version of the Python code
filenameNoName of the file (optional)unknown.py

Implementation Reference

  • Handler function for the compare_code_versions tool. Parses input using CompareCodeSchema, analyzes both original and revised code using the PythonAnalyzer, generates comparison report using generateComparisonReport helper, and returns it as MCP content.
    private async handleCompareCode(args: unknown) {
      const { originalCode, revisedCode, filename } = CompareCodeSchema.parse(args);
      
      const originalResult = this.analyzer.analyzePythonCode(originalCode, `${filename} (original)`);
      const revisedResult = this.analyzer.analyzePythonCode(revisedCode, `${filename} (revised)`);
      
      const comparisonReport = this.generateComparisonReport(originalResult, revisedResult);
      
      return {
        content: [
          {
            type: 'text',
            text: comparisonReport
          }
        ]
      };
    }
  • Zod input validation schema for the compare_code_versions tool, defining originalCode, revisedCode, and optional filename.
    const CompareCodeSchema = z.object({
      originalCode: z.string().min(1, "Original code cannot be empty"),
      revisedCode: z.string().min(1, "Revised code cannot be empty"),
      filename: z.string().optional().default("unknown.py")
    });
  • src/index.ts:154-176 (registration)
    Tool registration in the ListTools response, including name, description, and inputSchema matching the CompareCodeSchema.
    {
      name: 'compare_code_versions',
      description: 'Compare two versions of Python code to identify improvements or regressions in quality and security.',
      inputSchema: {
        type: 'object',
        properties: {
          originalCode: {
            type: 'string',
            description: 'Original version of the Python code'
          },
          revisedCode: {
            type: 'string',
            description: 'Revised version of the Python code'
          },
          filename: {
            type: 'string',
            description: 'Name of the file (optional)',
            default: 'unknown.py'
          }
        },
        required: ['originalCode', 'revisedCode']
      }
    },
  • Helper function that generates the detailed markdown comparison report, including metrics table, summary of improvements/regressions, and remaining issues.
    private generateComparisonReport(original: AnalysisResult, revised: AnalysisResult): string {
      const improvementScore = revised.codeQualityScore - original.codeQualityScore;
      const securityImprovement = revised.securityScore - original.securityScore;
      const issueImprovement = original.totalIssues - revised.totalIssues;
    
      const sections = [
        '🔄 **CODE COMPARISON REPORT**',
        '=' + '='.repeat(50),
        '',
        '## 📈 **IMPROVEMENT METRICS**',
        '',
        `| Metric | Original | Revised | Change |`,
        `|--------|----------|---------|--------|`,
        `| Quality Score | ${original.codeQualityScore}/100 | ${revised.codeQualityScore}/100 | ${this.formatChange(improvementScore)} |`,
        `| Security Score | ${original.securityScore}/100 | ${revised.securityScore}/100 | ${this.formatChange(securityImprovement)} |`,
        `| Total Issues | ${original.totalIssues} | ${revised.totalIssues} | ${this.formatChange(issueImprovement)} |`,
        `| Critical Issues | ${original.criticalIssues} | ${revised.criticalIssues} | ${this.formatChange(original.criticalIssues - revised.criticalIssues)} |`,
        '',
        this.generateComparisonSummary(improvementScore, securityImprovement, issueImprovement),
        '',
        this.generateRemainingIssues(revised)
      ];
    
      return sections.join('\n');
    }
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 tool compares code for quality and security, but doesn't explain how this comparison works, what metrics are used, whether it's read-only or has side effects, or what the output format is. For a tool with no annotation coverage, this leaves significant gaps in understanding its 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 with the core action and scope, making it easy to parse. Every part of the sentence contributes essential information, earning its place.

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 comparison and the lack of annotations and output schema, the description is insufficiently complete. It doesn't detail the comparison methodology, output format, or behavioral traits like error handling. For a tool with no structured data beyond the input schema, more context is needed to guide effective agent usage.

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 clear descriptions for all parameters (originalCode, revisedCode, filename). The description adds no additional semantic context beyond what the schema provides, such as explaining how the comparison uses these inputs or what 'filename' influences. With high schema coverage, the baseline score of 3 is appropriate as the schema handles parameter documentation adequately.

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: comparing two Python code versions to identify improvements or regressions in quality and security. It specifies the verb 'compare' and resource 'Python code versions' with the goal of evaluating quality and security. However, it doesn't explicitly differentiate from sibling tools like 'analyze_code_quality' or 'security_audit', which might have overlapping functionality.

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. It mentions identifying improvements or regressions, but doesn't specify contexts, prerequisites, or exclusions. With sibling tools like 'analyze_code_quality' and 'security_audit' available, the lack of differentiation leaves the agent uncertain 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/JJJHoons/python_code_review_mcp'

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