Skip to main content
Glama
JJJHoons

Python Code Review MCP Agent

by JJJHoons

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
NameRequiredDescriptionDefault
codeYesPython code to get improvement suggestions for
filenameNoName of the file (optional)unknown.py
focusAreaNoFocus area for suggestionsall

Implementation Reference

  • 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 } ] }; }
  • 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'] } }
  • 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);

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