Skip to main content
Glama

compare_commits

Compare two commits or branches to view file changes and diff statistics, showing what was added, modified, or removed between versions.

Instructions

Compare two commits or branches and see files changed.

Args:
    repo_slug: Repository slug
    base: Base commit hash or branch name
    head: Head commit hash or branch name

Returns:
    Diff statistics showing files added, modified, and removed

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_slugYes
baseYes
headYes

Implementation Reference

  • The MCP tool handler function for 'compare_commits'. It wraps the BitbucketClient's method, handles errors, formats output, and returns a summary of changed files with their status and line change counts.
    @mcp.tool()
    @handle_bitbucket_error
    @formatted
    def compare_commits(repo_slug: str, base: str, head: str) -> dict:
        """Compare two commits or branches and see files changed.
    
        Args:
            repo_slug: Repository slug
            base: Base commit hash or branch name
            head: Head commit hash or branch name
    
        Returns:
            Diff statistics showing files added, modified, and removed
        """
        client = get_client()
        result = client.compare_commits(repo_slug, base, head)
        if not result:
            return {"error": f"Could not compare {base}..{head}"}
    
        files = result.get("values", [])
        return {
            "files": [
                {
                    "path": f.get("new", {}).get("path") or f.get("old", {}).get("path"),
                    "status": f.get("status"),
                    "+": f.get("lines_added", 0),
                    "-": f.get("lines_removed", 0),
                }
                for f in files[:50]  # Limit to first 50 files
            ],
        }
  • The BitbucketClient helper method that makes the actual API call to Bitbucket's /diffstat endpoint to compare commits and retrieve diff statistics.
    def compare_commits(
        self,
        repo_slug: str,
        base: str,
        head: str,
    ) -> Optional[dict[str, Any]]:
        """Compare two commits or branches (get diff).
    
        Args:
            repo_slug: Repository slug
            base: Base commit/branch
            head: Head commit/branch
    
        Returns:
            Diff info including files changed
        """
        # Use diffstat for summary, diff for full content
        return self._request(
            "GET",
            self._repo_path(repo_slug, "diffstat", f"{base}..{head}"),
        )
  • src/server.py:796-796 (registration)
    The @mcp.tool() decorator registers the compare_commits function as an MCP tool.
    @mcp.tool()

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/JaviMaligno/mcp-server-bitbucket'

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