Skip to main content
Glama

Python Code Review MCP Agent

by JJJHoons

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

NameRequiredDescriptionDefault
codeYesPython code to get improvement suggestions for
filenameNoName of the file (optional)unknown.py
focusAreaNoFocus area for suggestionsall

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

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

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