Skip to content
Software capabilities

GitHub capability

Read a GitHub pull request diff

Use the diff media type for a raw REST response. The GitHub CLI and GitHub MCP server can fetch the same pull request changes from a terminal or agent.

Documentation reviewed

Ways to do it

API

GET /repos/{owner}/{repo}/pulls/{pull_number} with application/vnd.github.diff

Return the pull request’s diff as text using the Accept header.

Requirements
Repository owner, name, and pull request number. A fine-grained token for a private repository needs Pull requests read permission.
Limitations
A large diff can time out and return HTTP 5xx.
Read source: GitHub REST API get a pull request

CLI

gh pr diff <pull-request>

Print the pull request diff. Use --name-only to list files or --patch to request patch format.

Requirements
GitHub CLI authenticated for the repository and a pull request reference.
Limitations
Using --name-only omits the changed lines.

Example

gh pr diff "$PR_NUMBER" --repo "$OWNER/$REPO" --color never
Read source: GitHub CLI pull request diff

MCP

pull_request_read with method=get_diff

Give an MCP client the owner, repository, and pull request number to retrieve its diff.

Requirements
GitHub MCP server with the pull request read tool enabled and repository access.
Limitations
Available only if the connected server exposes the tool or method. Check the client’s tool list before relying on it.
Read source: GitHub MCP server tools