get_pull_request_diff
Retrieve code changes from a GitHub pull request to review modifications before merging.
Instructions
Get the diff for a pull request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner (username or organization) | |
| repo | Yes | Repository name | |
| pull_number | Yes | Pull request number |
Implementation Reference
- src/operations/pulls.ts:410-428 (handler)The main handler function that fetches the pull request diff using the GitHub API with a specific 'Accept: application/vnd.github.diff' header to retrieve 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 input schemas for validating the tool arguments: public schema without PAT and internal schema including the GitHub 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:306-310 (registration)Registration of the tool in the MCP server's listTools handler, 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 (registration)Dispatch logic in the MCP server's callToolRequest handler that parses arguments and calls the implementation function.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 }], }; }