get_pull_request_diff
Retrieve the changes in a pull request by specifying the repository owner, repository name, and pull request number. Utilize the MCP server for streamlined GitHub data access.
Instructions
Get the diff for a pull request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner (username or organization) | |
| pull_number | Yes | Pull request number | |
| repo | Yes | Repository name |
Implementation Reference
- src/operations/pulls.ts:410-428 (handler)Core handler function that retrieves the pull request diff by making a GitHub API request with the 'application/vnd.github.diff' Accept header, returning the raw diff as a string.export async function getPullRequestDiff( github_pat: string, owner: string, repo: string, pullNumber: number ): Promise<string> { const response = await githubRequest( github_pat, `https://api.github.com/repos/${owner}/${repo}/pulls/${pullNumber}`, { headers: { "Accept": "application/vnd.github.diff" } } ); // The response is already a string because the content type is not JSON return response as string; }
- src/operations/pulls.ts:195-203 (schema)Zod schemas defining the input parameters for the get_pull_request_diff tool: public schema without PAT and internal schema including PAT.export const GetPullRequestDiffSchema = z.object({ owner: z.string().describe("Repository owner (username or organization)"), repo: z.string().describe("Repository name"), pull_number: z.number().describe("Pull request number") }); export const _GetPullRequestDiffSchema = GetPullRequestDiffSchema.extend({ github_pat: z.string().describe("GitHub Personal Access Token"), });
- src/index.ts:307-310 (registration)Tool registration in the listTools response, specifying name, description, and input schema.name: "get_pull_request_diff", description: "Get the diff for a pull request", inputSchema: zodToJsonSchema(pulls.GetPullRequestDiffSchema), },
- src/index.ts:786-793 (handler)Dispatcher in the main CallToolRequest handler switch statement that parses arguments, calls the core handler, and formats the response.case "get_pull_request_diff": { const args = pulls._GetPullRequestDiffSchema.parse(params.arguments); const { github_pat, owner, repo, pull_number } = args; const result = await pulls.getPullRequestDiff(github_pat, owner, repo, pull_number); return { content: [{ type: "text", text: result }], }; }