Skip to main content
Glama

suggest_fix

Analyzes Python error messages to provide actionable fix suggestions, helping developers resolve coding issues efficiently.

Instructions

Suggest fixes for common Python errors based on error messages.

Analyzes error messages and provides actionable suggestions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
error_messageYes
code_contextNo

Implementation Reference

  • The implementation of the 'suggest_fix' MCP tool, which provides actionable suggestions for common Python errors based on error messages.
    async def suggest_fix(
        error_message: str,
        code_context: str | None = None,
        context: Context | None = None,
    ) -> dict[str, Any]:
        """
        Suggest fixes for common Python errors based on error messages.
    
        Analyzes error messages and provides actionable suggestions.
        """
        suggestions = []
    
        error_lower = error_message.lower()
    
        # Type error suggestions
        if "expected" in error_lower and "got" in error_lower:
            suggestions.append("Check the types of arguments being passed to functions")
            suggestions.append(
                "Consider adding type annotations to make expectations clear"
            )
    
        # Name error suggestions
        if "undefined name" in error_lower or "name error" in error_lower:
            # Extract the name if possible
            import re
    
            match = re.search(r"'(\w+)'", error_message)
            if match:
                name = match.group(1)
                # Check for similar names
                similar = session_tracker.similar_names.get(name, set())
                existing = [n for n in similar if n in session_tracker.identifiers]
                if existing:
                    suggestions.append(
                        f"Did you mean '{existing[0]}'? (found similar identifier)"
                    )
                else:
                    suggestions.append(f"Make sure '{name}' is defined before use")
                    suggestions.append("Check for typos in the identifier name")
    
        # Import error suggestions
        if "import" in error_lower:
            suggestions.append("Verify the module is installed: pip install <module>")
            suggestions.append("Check the import path is correct")
            suggestions.append("Ensure you're using the correct Python environment")
    
        # Attribute error suggestions
        if "attribute" in error_lower:
            suggestions.append(
                "Verify the object has the attribute you're trying to access"
            )
            suggestions.append("Check the object type matches your expectations")
            suggestions.append("Look for typos in the attribute name")
    
        # Indentation error suggestions
        if "indent" in error_lower:
            suggestions.append("Check that all code blocks are properly indented")
            suggestions.append("Ensure consistent use of spaces (not tabs)")
            suggestions.append("Verify indentation matches the logical structure")
    
        # Always add principled coding reminders
        principled_approach = [
            "",
            "=== PRINCIPLED CODING APPROACH ===",
            "🎯 Before implementing a fix:",
            "1. UNDERSTAND why this error happened - don't just make it go away",
            "2. CONSIDER if this reveals a design flaw that needs addressing",
            "3. CHECK for similar issues that might exist elsewhere",
            "4. IMPLEMENT a robust solution, not a quick hack",
            "5. DOCUMENT your fix so others understand the reasoning",
            "",
            "⚡ Remember: The path of least resistance often leads to technical debt!",
            "💡 Ask yourself: 'Am I fixing the symptom or the disease?'",
        ]
    
        return {
            "error": error_message,
            "suggestions": (
                suggestions
                if suggestions
                else ["No specific suggestions available for this error"]
            ),
            "has_suggestions": len(suggestions) > 0,
            "principled_approach": principled_approach,
        }

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/kimasplund/mcp-pyrefly'

If you have feedback or need assistance with the MCP directory API, please join our Discord server