get_pr_diff
Retrieve the diff content for a specific pull request in Bitbucket to review code changes between branches.
Instructions
Get the diff of a pull request.
Args:
repo_slug: Repository slug
pr_id: Pull request ID
Returns:
Diff content as text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_slug | Yes | ||
| pr_id | Yes |
Implementation Reference
- src/server.py:1062-1088 (handler)The main MCP tool handler for 'get_pr_diff'. Decorated with @mcp.tool() for registration, fetches the PR diff using the BitbucketClient, handles truncation for large diffs, and applies formatting and error handling.@mcp.tool() @handle_bitbucket_error @formatted def get_pr_diff(repo_slug: str, pr_id: int) -> dict: """Get the diff of a pull request. Args: repo_slug: Repository slug pr_id: Pull request ID Returns: Diff content as text """ client = get_client() diff = client.get_pr_diff(repo_slug, pr_id) if not diff: return {"error": f"PR #{pr_id} not found or has no diff"} # Truncate if too long max_length = 50000 truncated = len(diff) > max_length return { "pr_id": pr_id, "diff": diff[:max_length] if truncated else diff, "truncated": truncated, "total_length": len(diff), }
- src/bitbucket_client.py:1078-1092 (helper)Helper method in BitbucketClient that performs the actual API request to retrieve the pull request diff from Bitbucket's /pullrequests/{pr_id}/diff endpoint.def get_pr_diff( self, repo_slug: str, pr_id: int ) -> str: """Get diff of a pull request. Args: repo_slug: Repository slug pr_id: Pull request ID Returns: Diff content as string """ path = self._repo_path(repo_slug, "pullrequests", str(pr_id), "diff") return self._request_text(path) or ""