Skip to main content
Glama

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
NameRequiredDescriptionDefault
ownerYesRepository owner (username or organization)
repoYesRepository name
pull_numberYesPull request number

Implementation Reference

  • 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;
    }
  • 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 }],
      };
    }

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/MissionSquad/mcp-github'

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