Skip to main content
Glama

get_edit_preview

Preview code changes before applying them to verify edits in Python files using semantic analysis.

Instructions

Preview changes a code action would make.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
lineYes
columnYes
action_indexYes

Implementation Reference

  • The get_edit_preview tool handler that retrieves code actions and previews their edits.
    async def get_edit_preview(
        file_path: str, line: int, column: int, action_index: int
    ) -> str:
        """Preview changes a code action would make."""
        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}")
    
            if action_index < 1 or action_index > len(actions):
                return _error(f"Invalid index. Choose 1-{len(actions)}")
    
            action = actions[action_index - 1]
    
            if not action.edit:
                return _error(f"Action '{action.title}' has no edits")
    
            all_edits = action.edit.get_all_edits()
            total_edits = sum(len(e) for e in all_edits.values())
    
            preview = []
            for uri, edits in all_edits.items():
                edit_path = _uri_to_path(uri)
                for e in edits:
                    text_preview = e.new_text[:80].replace("\n", "\\n") if e.new_text else "(delete)"
                    preview.append({
                        "file": edit_path.name,
                        "line": e.range.start.line + 1,
                        "column": e.range.start.character + 1,
                        "new_text": text_preview
                    })
    
            return _ok({
                "action": action.title,
                "edits_count": total_edits,

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