get_improvement_suggestions
Receive actionable suggestions to enhance Python code quality, security, performance, and style. Analyze specific focus areas or address all aspects for optimized maintainability and efficiency.
Instructions
Get specific, actionable suggestions for improving Python code quality, security, and maintainability.
Input 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 |
Input Schema (JSON Schema)
{
"properties": {
"code": {
"description": "Python code to get improvement suggestions for",
"type": "string"
},
"filename": {
"default": "unknown.py",
"description": "Name of the file (optional)",
"type": "string"
},
"focusArea": {
"default": "all",
"description": "Focus area for suggestions",
"enum": [
"security",
"quality",
"performance",
"style",
"all"
],
"type": "string"
}
},
"required": [
"code"
],
"type": "object"
}
Implementation Reference
- src/index.ts:338-352 (handler)Primary handler for 'get_improvement_suggestions' tool: validates input, analyzes Python code using analyzer, generates focused suggestions, 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 input validation schema for the tool parameters (code, filename, focusArea).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:177-201 (registration)Tool registration in MCP server: defines name, description, and JSON schema for tool listing.{ 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)Key helper method that filters analysis issues by focus area, groups by line, formats suggestions 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'); }