Skip to main content
Glama

improve_test_case

Analyze test cases to identify issues and apply improvements with detailed suggestions and optional automatic fixes for better quality assurance.

Instructions

🔧 Analyze and improve a test case with detailed suggestions and optional automatic fixes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectKeyYesProject key (e.g., 'android' or 'ANDROID')
caseKeyYesTest case key (e.g., 'ANDROID-29')
rulesFilePathNoPath to custom rules markdown file
checkpointsFilePathNoPath to custom checkpoints markdown file
formatNoOutput formatmarkdown
applyHighConfidenceChangesNoAutomatically apply high-confidence improvements
include_clickable_linksNoInclude clickable links to Zebrunner web UI

Implementation Reference

  • The primary MCP tool handler for the 'improve_test_case' tool. Fetches the test case by key, validates it using TestCaseValidator, applies improvements via TestCaseImprover, optionally applies high-confidence changes, and formats the detailed improvement report.
    async improveTestCase(input: z.infer<typeof ImproveTestCaseInputSchema>) {
      const { projectKey, caseKey, rulesFilePath, checkpointsFilePath, format, applyHighConfidenceChanges } = input;
      
      try {
        // Get the test case data first
        const testCase = await this.client.getTestCaseByKey(projectKey, caseKey);
        
        // Initialize validator with dynamic rules
        let validator: TestCaseValidator;
        if (rulesFilePath && checkpointsFilePath) {
          // Use custom rules from files - validate paths first
          try {
            const resolvedRulesPath = validateFilePath(rulesFilePath, process.cwd());
            const resolvedCheckpointsPath = validateFilePath(checkpointsFilePath, process.cwd());
            validator = await TestCaseValidator.fromMarkdownFiles(resolvedRulesPath, resolvedCheckpointsPath);
          } catch (error) {
            throw new Error(`Invalid file path provided: ${error instanceof Error ? error.message : error}`);
          }
        } else {
          // Use default rules, but try to load from standard files if they exist
          const defaultRulesPath = path.resolve(process.cwd(), 'test_case_review_rules.md');
          const defaultCheckpointsPath = path.resolve(process.cwd(), 'test_case_analysis_checkpoints.md');
          
          try {
            validator = await TestCaseValidator.fromMarkdownFiles(defaultRulesPath, defaultCheckpointsPath);
          } catch (error) {
            // Fall back to default rules if files don't exist
            validator = new TestCaseValidator();
          }
        }
        
        // Validate the test case first
        const validationResult = await validator.validateTestCase(testCase);
        
        // Attempt improvement
        const improver = new TestCaseImprover();
        const improvementResult = await improver.improveTestCase(testCase, validationResult);
        
        // Apply high-confidence changes if requested
        let finalTestCase = testCase;
        if (applyHighConfidenceChanges && improvementResult.improvedTestCase) {
          finalTestCase = improvementResult.improvedTestCase;
        }
        
        // Format the result
        let formattedResult: string;
        
        if (format === 'markdown') {
          formattedResult = this.formatImprovementResultAsMarkdown(
            validationResult, 
            improvementResult, 
            finalTestCase, 
            applyHighConfidenceChanges
          );
        } else if (format === 'string') {
          formattedResult = this.formatImprovementResultAsString(
            validationResult, 
            improvementResult, 
            finalTestCase, 
            applyHighConfidenceChanges
          );
        } else {
          formattedResult = JSON.stringify({
            validation: validationResult,
            improvement: improvementResult,
            finalTestCase,
            changesApplied: applyHighConfidenceChanges
          }, null, 2);
        }
        
        return {
          content: [
            {
              type: "text" as const,
              text: formattedResult
            }
          ]
        };
      } catch (error: any) {
        const errorMsg = sanitizeErrorMessage(error, 'Error improving test case', 'improveTestCase');
        return {
          content: [
            {
              type: "text" as const,
              text: errorMsg
            }
          ]
        };
      }
    }
  • Zod input schema defining parameters for the improve_test_case tool: projectKey, caseKey, optional rules/checkpoints files, output format, and whether to auto-apply high-confidence improvements.
    export const ImproveTestCaseInputSchema = z.object({
      projectKey: z.string().min(1),
      caseKey: z.string().min(1),
      rulesFilePath: z.string().optional(),
      checkpointsFilePath: z.string().optional(),
      format: z.enum(['dto', 'json', 'string', 'markdown']).default('markdown'),
      applyHighConfidenceChanges: z.boolean().default(true)
    });
  • Core helper function in TestCaseImprover class that analyzes validation issues and generates targeted improvements (title fixes, preconditions, expected results, language clarity, structure). Applies automatic changes and flags human-needed ones.
    async improveTestCase(
      originalTestCase: ZebrunnerTestCase, 
      validationResult: ValidationResult
    ): Promise<ImprovementResult> {
      const improvements: ImprovementSuggestion[] = [];
      const humanHelpReasons: string[] = [];
      let improvedTestCase = JSON.parse(JSON.stringify(originalTestCase)); // Deep clone
      let canImprove = false;
      let requiresHumanHelp = false;
    
      // Process each validation issue
      for (const issue of validationResult.issues) {
        const improvement = await this.processIssue(issue, originalTestCase, improvedTestCase);
        
        if (improvement) {
          improvements.push(improvement);
          canImprove = true;
          
          // Apply the improvement if it's automatic or high confidence
          if (improvement.type === 'automatic' || improvement.confidence === 'high') {
            this.applyImprovement(improvement, improvedTestCase);
          }
        } else {
          // Issue requires human help
          requiresHumanHelp = true;
          humanHelpReasons.push(`${issue.category}: ${issue.description}`);
        }
      }
    
      // Additional structural improvements
      const structuralImprovements = this.suggestStructuralImprovements(originalTestCase);
      improvements.push(...structuralImprovements);
      
      if (structuralImprovements.length > 0) {
        canImprove = true;
        // Apply high-confidence structural improvements
        structuralImprovements
          .filter(imp => imp.confidence === 'high')
          .forEach(imp => this.applyImprovement(imp, improvedTestCase));
      }
    
      // Determine overall confidence
      const overallConfidence = this.calculateOverallConfidence(improvements);
    
      return {
        canImprove,
        requiresHumanHelp,
        confidence: overallConfidence,
        improvements,
        improvedTestCase: canImprove ? improvedTestCase : undefined,
        humanHelpReasons
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only vaguely mentions 'optional automatic fixes' without detailing what changes are made, permissions required, or side effects. It doesn't specify if improvements are saved automatically, require review, or affect other test cases, leaving key behavioral traits unclear.

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 that front-loads the core purpose. It uses an emoji for visual emphasis but avoids unnecessary elaboration, though it could be slightly more structured by separating analysis from fixes.

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

Completeness3/5

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

For a tool with 7 parameters, no annotations, and no output schema, the description is minimally adequate. It covers the basic purpose but lacks details on behavior, output format implications, or integration with sibling tools, leaving gaps in understanding how to effectively use it.

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 fully documents all 7 parameters. The description adds no additional meaning beyond what's in the schema, such as explaining how 'rulesFilePath' or 'checkpointsFilePath' influence analysis. Baseline 3 is appropriate since 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 action ('analyze and improve') and resource ('test case'), with additional detail about providing 'detailed suggestions and optional automatic fixes'. It distinguishes from siblings like 'validate_test_case' or 'get_test_case_by_key' by focusing on enhancement rather than retrieval or validation, though it doesn't explicitly name 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?

No guidance is provided on when to use this tool versus alternatives like 'validate_test_case' or 'get_enhanced_test_coverage_with_rules'. The description implies usage for test case improvement but lacks context on prerequisites, constraints, or specific scenarios where it's most appropriate.

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/maksimsarychau/mcp-zebrunner'

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