get_improvement_suggestions
Analyze Python code to generate specific suggestions for improving quality, security, performance, and maintainability.
Instructions
Get specific, actionable suggestions for improving Python code quality, security, and maintainability.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python code to get improvement suggestions for | |
| filename | No | Name of the file (optional) | unknown.py |
| focusArea | No | Focus area for suggestions | all |
Implementation Reference
- src/index.ts:338-352 (handler)Main handler function for 'get_improvement_suggestions' tool. Parses input using GetSuggestionsSchema, analyzes code with analyzer, generates focused suggestions, and returns formatted text response.private async handleGetSuggestions(args: unknown) { const { code, filename, focusArea } = GetSuggestionsSchema.parse(args); const result = this.analyzer.analyzePythonCode(code, filename); const suggestions = this.generateFocusedSuggestions(result, focusArea); return { content: [ { type: 'text', text: suggestions } ] }; }
- src/index.ts:50-54 (schema)Zod schema for input validation of the get_improvement_suggestions tool parameters: code (required), filename (optional), focusArea (optional enum).const GetSuggestionsSchema = z.object({ code: z.string().min(1, "Code cannot be empty"), filename: z.string().optional().default("unknown.py"), focusArea: z.enum(["security", "quality", "performance", "style", "all"]).optional().default("all") });
- src/index.ts:178-201 (registration)Tool registration in the MCP server tools list, including name, description, and JSON input schema matching the Zod schema.name: 'get_improvement_suggestions', description: 'Get specific, actionable suggestions for improving Python code quality, security, and maintainability.', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Python code to get improvement suggestions for' }, filename: { type: 'string', description: 'Name of the file (optional)', default: 'unknown.py' }, focusArea: { type: 'string', enum: ['security', 'quality', 'performance', 'style', 'all'], description: 'Focus area for suggestions', default: 'all' } }, required: ['code'] } }
- src/index.ts:434-480 (helper)Core helper function that generates focused improvement suggestions by filtering issues by focusArea, grouping by line, formatting with severity icons and best practices.private generateFocusedSuggestions(result: AnalysisResult, focusArea: string): string { const sections = [ `๐ก **${focusArea.toUpperCase()} IMPROVEMENT SUGGESTIONS**`, '=' + '='.repeat(50), `**File:** ${result.fileName}`, '' ]; let relevantIssues = result.issues; if (focusArea !== 'all') { if (focusArea === 'style') { relevantIssues = result.issues.filter(i => i.type === 'style' || i.rule.includes('naming-convention') ); } else { relevantIssues = result.issues.filter(i => i.type === focusArea); } } if (relevantIssues.length === 0) { sections.push(`โ No ${focusArea} issues found! Your code looks good in this area.`); sections.push(''); sections.push('## ๐ **GENERAL BEST PRACTICES:**'); sections.push(this.getGeneralBestPractices(focusArea)); return sections.join('\n'); } sections.push(`## ๐ฏ **${focusArea.toUpperCase()} ISSUES TO ADDRESS (${relevantIssues.length})**`); sections.push(''); const groupedByLine = this.groupIssuesByLine(relevantIssues); Object.entries(groupedByLine).forEach(([line, issues]) => { sections.push(`### Line ${line}:`); issues.forEach(issue => { sections.push(`- ${this.getSeverityIcon(issue.severity)} **${issue.message}**`); if (issue.suggestion) { sections.push(` ๐ก *${issue.suggestion}*`); } }); sections.push(''); }); sections.push(this.getFocusAreaBestPractices(focusArea)); return sections.join('\n'); }
- src/index.ts:223-225 (registration)Dispatch case in the tool request handler switch statement that routes to the specific handler.case 'get_improvement_suggestions': return await this.handleGetSuggestions(args);