review_and_enhance_code
Analyze generated code to add improvements, documentation, validation, POM patterns, and reusable functions for better maintainability.
Instructions
Review generated code and enhance it with improvements, documentation, validation, POM patterns, and reusable functions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_paths | Yes | Paths to the generated files to review | |
| review_criteria | No | Specific review criteria (docs, pom, functions, utils, format, existing_steps) | |
| repo_path | No | Repository path for checking existing functions and patterns |
Implementation Reference
- index.js:1067-1095 (handler)The primary handler function for the 'review_and_enhance_code' MCP tool. It processes each file in file_paths, reads the content, invokes performCodeReview for analysis and enhancement, applies changes by writing enhanced_content back to files, and returns a summary of reviews.async reviewAndEnhanceCode(args) { const { file_paths, review_criteria = ['docs', 'pom', 'functions', 'utils', 'format', 'existing_steps'], repo_path } = args; try { const reviews = []; for (const filePath of file_paths) { const content = await fs.readFile(filePath, 'utf8'); const review = await this.performCodeReview(content, review_criteria, repo_path, filePath); reviews.push({ file: filePath, review }); // Apply enhancements if (review.enhanced_content) { await fs.writeFile(filePath, review.enhanced_content); } } return { content: [ { type: 'text', text: `Code review and enhancement complete:\n\n${JSON.stringify(reviews, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to review and enhance code: ${error.message}`); } }
- index.js:1899-1958 (helper)Core helper method performing detailed code review based on specified criteria. Analyzes repository patterns if provided, invokes specific review methods (docs, pom, functions, etc.), collects issues/suggestions/improvements, applies enhancements, and computes a quality score.async performCodeReview(content, review_criteria, repo_path, filePath) { const review = { issues: [], suggestions: [], enhanced_content: content, score: 100, improvements: [] }; try { // Get existing patterns from repository if available let repoPatterns = {}; if (repo_path) { try { const analysisResult = await this.analyzeRepositoryPatterns({ repo_path, pattern_types: ['features', 'steps', 'pages', 'components'] }); repoPatterns = JSON.parse(analysisResult.content[0].text).patterns || {}; } catch (error) { console.warn(`Could not analyze repository patterns: ${error.message}`); } } // Perform review based on criteria for (const criteria of review_criteria) { switch (criteria) { case 'docs': this.reviewDocumentation(content, review, filePath); break; case 'pom': this.reviewPageObjectModel(content, review, filePath); break; case 'functions': this.reviewFunctionQuality(content, review, filePath); break; case 'utils': this.reviewUtilityUsage(content, review, repoPatterns); break; case 'format': this.reviewCodeFormatting(content, review); break; case 'existing_steps': this.reviewStepReuse(content, review, repoPatterns); break; } } // Apply enhancements to content review.enhanced_content = this.applyEnhancements(content, review.improvements); // Calculate final score review.score = Math.max(0, 100 - (review.issues.length * 10) - (review.suggestions.length * 5)); } catch (error) { review.issues.push(`Review process failed: ${error.message}`); } return review; }
- index.js:296-321 (schema)JSON Schema defining the input parameters for the 'review_and_enhance_code' tool, including file_paths (required array of strings), review_criteria (enum array with defaults), and optional repo_path.inputSchema: { type: 'object', properties: { file_paths: { type: 'array', items: { type: 'string', minLength: 1 }, description: 'Paths to the generated files to review', minItems: 1, }, review_criteria: { type: 'array', items: { type: 'string', enum: ['docs', 'pom', 'functions', 'utils', 'format', 'existing_steps'] }, description: 'Specific review criteria (docs, pom, functions, utils, format, existing_steps)', default: ['docs', 'pom', 'functions', 'utils', 'format', 'existing_steps'], }, repo_path: { type: 'string', description: 'Repository path for checking existing functions and patterns', }, }, required: ['file_paths'], additionalProperties: false, },
- index.js:356-357 (registration)Tool dispatch/registration in the CallToolRequestSchema handler switch statement, mapping the tool name to its handler method.case 'review_and_enhance_code': return await this.reviewAndEnhanceCode(args);
- index.js:330-334 (registration)Registration of ListToolsRequestSchema handler that returns the tool list including 'review_and_enhance_code' with its schema and description.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolConfigs, }; });