Skip to main content
Glama

get_code_actions

Retrieve quick fixes and refactorings for Python code at specific positions to improve code quality and resolve issues.

Instructions

Get available quick fixes and refactorings at position (1-based).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
columnYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • This function is the MCP tool handler 'get_code_actions', which gets diagnostics for a file path and calls the underlying LSP client to retrieve code actions.
    @mcp.tool()
    async def get_code_actions(file_path: str, line: int, column: int) -> str:
        """Get available quick fixes and refactorings at position (1-based)."""
        client = _get_client()
    
        path = Path(file_path).resolve()
        if not path.exists():
            return _error(f"File not found: {file_path}")
    
        try:
            await client.open_document(path)
    
            import asyncio
            await asyncio.sleep(0.3)
    
            diagnostics = client.get_diagnostics(path)
            relevant_diags = [
                d for d in diagnostics
                if d.range.start.line <= line - 1 <= d.range.end.line
            ]
    
            actions = await client.get_code_actions(
                path, line - 1, column - 1, line - 1, column, relevant_diags
            )
    
            if not actions:
                return _not_found(f"No actions at {path.name}:{line}:{column}")
    
            action_list = []
            for i, action in enumerate(actions, 1):
                action_list.append({
                    "index": i,
                    "title": action.title,
                    "kind": action.kind or None,
                    "has_edit": action.edit is not None
                })
    
            return _ok({"count": len(actions), "actions": action_list})
    
        except Exception as e:
            return _error(str(e))
  • This is the underlying LSP client method that performs the actual communication with the language server to get code actions.
    async def get_code_actions(
        self, file_path: str | Path, start_line: int, start_char: int,
        end_line: int, end_char: int, diagnostics: list[Diagnostic] | None = None
    ) -> list[CodeAction]:
        """Get available code actions (quick fixes, refactorings) for a range."""
        file_path = Path(file_path).resolve()
        uri = file_path.as_uri()
    
        context: dict[str, Any] = {"diagnostics": []}
        if diagnostics:
            for diag in diagnostics:
                context["diagnostics"].append({
                    "range": diag.range.to_dict(),
                    "message": diag.message,
                    "severity": diag.severity,
                    "source": diag.source,
                    "code": diag.code
                })
    
        result = await self._send_request("textDocument/codeAction", {
            "textDocument": {"uri": uri},
            "range": {
                "start": {"line": start_line, "character": start_char},
                "end": {"line": end_line, "character": end_char}
            },
            "context": context
        })
    
        if not result:
            return []
    
        actions = []
        for item in result:
Behavior3/5

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

No annotations provided, so description carries full burden. Adds critical '1-based' indexing note for line/column parameters. However, fails to indicate this is read-only (safe to call), whether it requires an active project (implied by siblings), or the nature of the returned action objects.

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?

Single sentence, front-loaded with verb, no unnecessary words. However, brevity comes at cost of missing necessary behavioral and usage context, suggesting it is under-sized for the tool's complexity rather than optimally concise.

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

Completeness2/5

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

Despite having an output schema (reducing description burden for return values), the description inadequately covers the 0% schema-described parameters and fails to establish the critical sibling workflow (get_code_actions → apply_code_action). Lacks completeness expected for a 3-parameter LSP-like tool with no safety annotations.

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

Parameters3/5

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

Schema has 0% description coverage. Description implies line/column via 'position' and adds the '1-based' constraint, but completely omits file_path semantics (e.g., absolute vs relative path requirements). Provides partial compensation for the schema 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?

Clear verb ('Get') and resource ('quick fixes and refactorings'), with scope ('at position'). Distinguishes from get_diagnostics (which gets problems, not fixes) by nature of the return value, but does not explicitly clarify the workflow relationship with sibling apply_code_action.

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?

No guidance on when to use this tool versus siblings, or that it should typically be invoked after get_diagnostics when fixes are available. Missing explicit note that apply_code_action must be called separately to execute any returned actions.

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/qinsehm1128/mcp-ty'

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