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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

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,
        }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions analyzing error messages and providing actionable suggestions, but lacks details on traits like whether it's read-only or mutative, error handling, rate limits, or authentication needs. For a tool with no annotations, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with two concise sentences that front-load the core purpose. Each sentence adds value: the first states the main function, and the second elaborates on the analysis process. There's no wasted text, making it efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (error analysis), no annotations, and an output schema (which reduces the need to describe return values), the description is partially complete. It covers the basic purpose but lacks details on behavioral traits and parameter semantics. With schema coverage at 0% and no annotations, it should do more to compensate, but the presence of an output schema slightly mitigates this.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning parameters are undocumented in the schema. The description doesn't add any meaning beyond the parameter names ('error_message' and 'code_context'), such as explaining what constitutes a valid error message or how code context influences suggestions. With two parameters and no schema descriptions, the description fails to compensate for this gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Suggest fixes for common Python errors based on error messages' and 'Analyzes error messages and provides actionable suggestions.' It specifies the verb ('suggest fixes'), resource ('Python errors'), and method ('based on error messages'). However, it doesn't explicitly differentiate from sibling tools like 'check_code' or 'submit_fixed_code', which might have overlapping functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance on when to use this tool, only implying it's for Python error analysis. It doesn't specify when to use it versus alternatives like 'check_code' (which might check code without errors) or 'submit_fixed_code' (which might submit fixes after suggestions). No explicit exclusions or prerequisites are mentioned, leaving usage context vague.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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