get_commit_diff
Compare code changes between commits, branches, or tags in GitHub repositories to analyze differences, review pull requests, or check version updates.
Instructions
Get the diff between two commits, branches, or tags in a GitHub repository.
USE THIS WHEN: You need to see what changed between two versions of code.
BEST FOR: Analyzing changes, reviewing pull requests (by comparing branches), or checking version differences.
Returns the raw git diff output.
Args:
repo: Repository in format "owner/repo" (e.g., "psf/requests")
base: Base commit SHA, branch name, or tag (e.g., "main", "v1.0.0", "a1b2c3d")
head: Head commit SHA, branch name, or tag (e.g., "feature-branch", "v1.1.0", "e5f6g7h")
Returns:
JSON with the raw git diff content.
Example: get_commit_diff("psf/requests", "v2.28.0", "v2.28.1") → Returns diff between versions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo | Yes | ||
| base | Yes | ||
| head | Yes |
Implementation Reference
- src/RTFD/providers/github.py:894-927 (handler)Main handler function for the 'get_commit_diff' MCP tool. Parses the repository string, validates format, calls the private helper to fetch the diff from GitHub API, and returns a serialized CallToolResult.async def get_commit_diff(repo: str, base: str, head: str) -> CallToolResult: """ Get the diff between two commits, branches, or tags in a GitHub repository. USE THIS WHEN: You need to see what changed between two versions of code. BEST FOR: Analyzing changes, reviewing pull requests (by comparing branches), or checking version differences. Returns the raw git diff output. Args: repo: Repository in format "owner/repo" (e.g., "psf/requests") base: Base commit SHA, branch name, or tag (e.g., "main", "v1.0.0", "a1b2c3d") head: Head commit SHA, branch name, or tag (e.g., "feature-branch", "v1.1.0", "e5f6g7h") Returns: JSON with the raw git diff content. Example: get_commit_diff("psf/requests", "v2.28.0", "v2.28.1") → Returns diff between versions """ parts = repo.split("/", 1) if len(parts) != 2: error_result = { "repository": repo, "base": base, "head": head, "diff": "", "error": "Invalid repo format. Use 'owner/repo'", } return serialize_response_with_meta(error_result) owner, repo_name = parts result = await self._get_commit_diff(owner, repo_name, base, head) return serialize_response_with_meta(result)
- src/RTFD/providers/github.py:439-487 (helper)Private helper method that performs the actual API call to GitHub's compare endpoint to retrieve the raw diff between base and head commits, with error handling.async def _get_commit_diff(self, owner: str, repo: str, base: str, head: str) -> dict[str, Any]: """ Get the diff between two commits. Args: owner: Repository owner repo: Repository name base: Base commit/branch/tag head: Head commit/branch/tag Returns: Dict with diff content """ try: headers = self._get_headers() # Request raw diff format headers["Accept"] = "application/vnd.github.diff" url = f"https://api.github.com/repos/{owner}/{repo}/compare/{base}...{head}" async with await self._http_client() as client: resp = await client.get(url, headers=headers) resp.raise_for_status() diff_content = resp.text return { "repository": f"{owner}/{repo}", "base": base, "head": head, "diff": diff_content, "size_bytes": len(diff_content.encode("utf-8")), } except httpx.HTTPStatusError as exc: return { "repository": f"{owner}/{repo}", "base": base, "head": head, "diff": "", "error": f"GitHub returned {exc.response.status_code}", } except Exception as exc: return { "repository": f"{owner}/{repo}", "base": base, "head": head, "diff": "", "error": f"Failed to get diff: {exc!s}", }
- src/RTFD/providers/github.py:928-941 (registration)Registration of the 'get_commit_diff' tool (and others) in the tools dictionary returned by GitHubProvider.get_tools(), conditionally if fetch is enabled.tools = { "github_repo_search": github_repo_search, "github_code_search": github_code_search, "list_github_packages": list_github_packages, "get_package_versions": get_package_versions, } if is_fetch_enabled(): tools["fetch_github_readme"] = fetch_github_readme tools["list_repo_contents"] = list_repo_contents tools["get_file_content"] = get_file_content tools["get_repo_tree"] = get_repo_tree tools["get_commit_diff"] = get_commit_diff return tools
- src/RTFD/providers/github.py:20-43 (registration)Declaration of 'get_commit_diff' in the tool_names list within the provider metadata, conditionally included if fetch is enabled.def get_metadata(self) -> ProviderMetadata: tool_names = ["github_repo_search", "github_code_search"] if is_fetch_enabled(): tool_names.extend( [ "fetch_github_readme", "list_repo_contents", "get_file_content", "get_repo_tree", "get_commit_diff", "list_github_packages", "get_package_versions", ] ) return ProviderMetadata( name="github", description="GitHub repository and code search, file browsing, and content fetching", expose_as_tool=True, tool_names=tool_names, supports_library_search=True, required_env_vars=[], optional_env_vars=["GITHUB_TOKEN", "GITHUB_AUTH"], )