Skip to content

Diff

diff

MCP tool for structural branch diff.

DiffTool

Bases: AXMTool

Compare two git refs at symbol level.

Registered as ast_diff via axm.tools entry point. Uses git worktrees to avoid disturbing the working tree.

Source code in packages/axm-ast/src/axm_ast/tools/diff.py
Python
class DiffTool(AXMTool):
    """Compare two git refs at symbol level.

    Registered as ``ast_diff`` via axm.tools entry point.
    Uses git worktrees to avoid disturbing the working tree.
    """

    @property
    def name(self) -> str:
        """Return tool name for registry lookup."""
        return "ast_diff"

    @safe_execute
    def execute(
        self,
        *,
        path: str = ".",
        base: str = "",
        head: str = "",
        **kwargs: object,
    ) -> ToolResult:
        """Compare two branches at symbol level.

        Args:
            path: Path to package directory.
            base: Base git ref (branch, tag, commit).
            head: Head git ref (branch, tag, commit).

        Returns:
            ToolResult with structural diff data.
        """
        if not base:
            return ToolResult(success=False, error="base parameter is required")
        if not head:
            return ToolResult(success=False, error="head parameter is required")

        project_path = Path(path).resolve()
        if not project_path.is_dir():
            return ToolResult(success=False, error=f"Not a directory: {project_path}")

        from axm_ast.core.structural_diff import structural_diff

        result = structural_diff(project_path, base, head)

        if "error" in result:
            err = result["error"]
            return ToolResult(
                success=False,
                error=err if isinstance(err, str) else str(err),
            )

        return ToolResult(
            success=True,
            data=cast("dict[str, object]", result),
        )
name property

Return tool name for registry lookup.

execute(*, path='.', base='', head='', **kwargs)

Compare two branches at symbol level.

Parameters:

Name Type Description Default
path str

Path to package directory.

'.'
base str

Base git ref (branch, tag, commit).

''
head str

Head git ref (branch, tag, commit).

''

Returns:

Type Description
ToolResult

ToolResult with structural diff data.

Source code in packages/axm-ast/src/axm_ast/tools/diff.py
Python
@safe_execute
def execute(
    self,
    *,
    path: str = ".",
    base: str = "",
    head: str = "",
    **kwargs: object,
) -> ToolResult:
    """Compare two branches at symbol level.

    Args:
        path: Path to package directory.
        base: Base git ref (branch, tag, commit).
        head: Head git ref (branch, tag, commit).

    Returns:
        ToolResult with structural diff data.
    """
    if not base:
        return ToolResult(success=False, error="base parameter is required")
    if not head:
        return ToolResult(success=False, error="head parameter is required")

    project_path = Path(path).resolve()
    if not project_path.is_dir():
        return ToolResult(success=False, error=f"Not a directory: {project_path}")

    from axm_ast.core.structural_diff import structural_diff

    result = structural_diff(project_path, base, head)

    if "error" in result:
        err = result["error"]
        return ToolResult(
            success=False,
            error=err if isinstance(err, str) else str(err),
        )

    return ToolResult(
        success=True,
        data=cast("dict[str, object]", result),
    )