Skip to main content
Glama

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
NameRequiredDescriptionDefault
pr_numberYes
repo_nameYes
repo_ownerYes

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)
  • 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)
  • 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)

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/saidsef/mcp-github-pr-issue-analyser'

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