get_github_pr_diff
Fetch the diff of a specific pull request from a GitHub repository by providing the repo owner, name, and PR number. Returns the changes as a string or an error message if issues occur.
Instructions
Fetches the diff of a specific pull request from a GitHub repository.
Args:
repo_owner (str): The owner of the GitHub repository.
repo_name (str): The name of the GitHub repository.
pr_number (int): The pull request number to fetch the diff for.
Returns:
str: The diff of the pull request as a string. Returns an empty string if no changes are found,
or an error message string if an exception occurs.
Error Handling:
Logs and returns the error message if an exception is raised during the fetch operation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pr_number | Yes | ||
| repo_name | Yes | ||
| repo_owner | Yes |
Implementation Reference
- The core handler function `get_pr_diff` in GitHubIntegration class that fetches and returns the raw patch/diff for a GitHub pull request using the patch-diff.githubusercontent.com endpoint. This is the exact implementation of the PR diff fetching logic.def get_pr_diff(self, repo_owner: str, repo_name: str, pr_number: int) -> str: """ Fetches the diff/patch of a specific pull request from a GitHub repository. Args: repo_owner (str): The owner of the GitHub repository. repo_name (str): The name of the GitHub repository. pr_number (int): The pull request number. Returns: str: The raw patch/diff text of the pull request if successful, otherwise None. Error Handling: Logs an error message and prints the traceback if the request fails or an exception occurs. """ logging.info(f"Fetching PR diff for {repo_owner}/{repo_name}#{pr_number}") try: # Fetch PR details response = requests.get(f"https://patch-diff.githubusercontent.com/raw/{repo_owner}/{repo_name}/pull/{pr_number}.patch", headers=self._get_headers(), timeout=TIMEOUT) response.raise_for_status() pr_patch = response.text logging.info("Successfully fetched PR diff/patch") return pr_patch except Exception as e: logging.error(f"Error fetching PR diff: {str(e)}") traceback.print_exc() return str(e)
- src/mcp_github/issues_pr_analyser.py:109-113 (registration)Dynamic registration of all public methods from GitHubIntegration (including `get_pr_diff`) as MCP tools via `FastMCP.add_tool(method)`. The tool name matches the method name `get_pr_diff`.def register_tools(self, methods: Any = None) -> None: for name, method in inspect.getmembers(methods): if (inspect.isfunction(method) or inspect.ismethod(method)) and not name.startswith("_"): self.mcp.add_tool(method)
- src/mcp_github/issues_pr_analyser.py:106-107 (registration)Calls `register_tools` on the GitHubIntegration instance (`self.gi`), which registers `get_pr_diff` among other methods as MCP tools.self.register_tools(self.gi) self.register_tools(self.ip)