Skip to main content
Glama
gourav221b

GitHub PR MCP Server

by gourav221b

get-pull-request-data

Extract comprehensive GitHub Pull Request details, including files, diffs, comments, and reviews, for efficient analysis and review processes.

Instructions

Get detailed information about a GitHub Pull Request including files, diff, comments, and reviews

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesGitHub repository owner
pullNumberYesPull request number
repoYesGitHub repository name
tokenNoGitHub personal access token (optional)

Implementation Reference

  • The asynchronous handler function for the 'get-pull-request-data' tool. It initializes the Octokit client, fetches PR data using the helper function, and returns formatted JSON or error response.
    async ({ owner, repo, pullNumber, token }) => {
        try {
            // Initialize Octokit with token if provided
            const octokit = new Octokit({
                auth: token,
                baseUrl: GITHUB_API_BASE,
            });
    
            // Get all PR information
            const prData = await getAllPullRequestInfo(octokit, owner, repo, pullNumber);
    
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify(prData, null, 2)
                    }
                ]
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Error: ${error instanceof Error ? error.message : "An unknown error occurred"}`
                    }
                ],
                isError: true
            };
        }
    }
  • Zod input schema defining the parameters for the 'get-pull-request-data' tool: owner, repo, pullNumber, and optional token.
    {
        owner: z.string().describe("GitHub repository owner"),
        repo: z.string().describe("GitHub repository name"),
        pullNumber: z.number().describe("Pull request number"),
        token: z.string().optional().describe("GitHub personal access token (optional)"),
    },
  • src/index.ts:17-57 (registration)
    Registration of the 'get-pull-request-data' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool(
        "get-pull-request-data",
        "Get detailed information about a GitHub Pull Request including files, diff, comments, and reviews",
        {
            owner: z.string().describe("GitHub repository owner"),
            repo: z.string().describe("GitHub repository name"),
            pullNumber: z.number().describe("Pull request number"),
            token: z.string().optional().describe("GitHub personal access token (optional)"),
        },
        async ({ owner, repo, pullNumber, token }) => {
            try {
                // Initialize Octokit with token if provided
                const octokit = new Octokit({
                    auth: token,
                    baseUrl: GITHUB_API_BASE,
                });
    
                // Get all PR information
                const prData = await getAllPullRequestInfo(octokit, owner, repo, pullNumber);
    
                return {
                    content: [
                        {
                            type: "text",
                            text: JSON.stringify(prData, null, 2)
                        }
                    ]
                };
            } catch (error) {
                return {
                    content: [
                        {
                            type: "text",
                            text: `Error: ${error instanceof Error ? error.message : "An unknown error occurred"}`
                        }
                    ],
                    isError: true
                };
            }
        }
    );
  • Helper function that fetches comprehensive Pull Request data by calling sub-helpers for details, diff, comments, and reviews in parallel.
    export async function getAllPullRequestInfo(
        octokit: Octokit,
        owner: string,
        repo: string,
        pullNumber: number
    ): Promise<{
        details: PullRequestDetails;
        diff: string;
        comments: any[];
    
    }> {
        const [details, diff, comments,] = await Promise.all([
            getPullRequestDetails(octokit, owner, repo, pullNumber),
    
            getPullRequestDiff(octokit, owner, repo, pullNumber),
            getPullRequestComments(octokit, owner, repo, pullNumber),
            getPullRequestReviews(octokit, owner, repo, pullNumber),
        ]);
    
        return {
            details,
            diff,
            comments,
    
        };
    }
Install Server

Other Tools

Related Tools

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/gourav221b/Github-PR-MCP-server'

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