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
| Name | Required | Description | Default |
|---|---|---|---|
| repo_slug | Yes | ||
| base | Yes | ||
| head | Yes |
Implementation Reference
- src/server.py:796-827 (handler)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 ], }
- src/bitbucket_client.py:864-884 (helper)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()