Skip to main content
Glama
ddukbg

GitHub Enterprise MCP Server

list-pull-requests

Retrieve pull requests from GitHub Enterprise repositories with filters for state, sorting, and pagination to manage code review workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesRepository owner (user or organization)
repoYesRepository name
stateNoPR state filteropen
sortNoSort criteriacreated
directionNoSort directiondesc
pageNoPage number
per_pageNoItems per page

Implementation Reference

  • Registration of the MCP tool named 'list-pull-requests'
    server.tool( "list-pull-requests",
  • Input schema for 'list-pull-requests' tool defined using Zod
    { owner: z.string().describe("Repository owner (user or organization)"), repo: z.string().describe("Repository name"), state: z.enum(['open', 'closed', 'all']).default('open').describe("PR state filter"), sort: z.enum(['created', 'updated', 'popularity', 'long-running']).default('created').describe("Sort criteria"), direction: z.enum(['asc', 'desc']).default('desc').describe("Sort direction"), page: z.number().default(1).describe("Page number"), per_page: z.number().default(30).describe("Items per page") },
  • Handler function for 'list-pull-requests' tool: validates input, calls GitHub API via helper, formats and returns PR list or error
    async ({ owner, repo, state, sort, direction, page, per_page }) => { try { // Parameter validation if (!owner || typeof owner !== 'string' || owner.trim() === '') { return { content: [ { type: "text", text: "Error: Repository owner (owner) is required." } ], isError: true }; } if (!repo || typeof repo !== 'string' || repo.trim() === '') { return { content: [ { type: "text", text: "Error: Repository name (repo) is required." } ], isError: true }; } const pullRequests = await context.pulls.listPullRequests(context.client, { owner, repo, state, sort, direction, page, per_page }); // No PRs found if (!pullRequests || pullRequests.length === 0) { return { content: [ { type: "text", text: `No pull requests found in repository '${owner}/${repo}' with state '${state}'.` } ] }; } // Format PR info for better readability const formattedPRs = pullRequests.map(pr => ({ number: pr.number, title: pr.title, state: pr.state, user: pr.user.login, created_at: pr.created_at, updated_at: pr.updated_at, head: `${pr.head.repo.full_name}:${pr.head.ref}`, base: `${pr.base.repo.full_name}:${pr.base.ref}`, url: `${pr.number}` })); return { content: [ { type: "text", text: `Pull requests in repository '${owner}/${repo}' (${pullRequests.length}):\n\n${JSON.stringify(formattedPRs, null, 2)}` } ] }; } catch (error: any) { console.error('Error fetching pull requests:', error); return { content: [ { type: "text", text: `An error occurred while fetching pull requests: ${error.message}` } ], isError: true }; } } );
  • Helper function implementing the GitHub API call to list pull requests for a repository
    export async function listPullRequests( client: GitHubClient, params: ListPullRequestsParams ): Promise<PullRequest[]> { const { owner, repo, state = 'open', sort = 'created', direction = 'desc', page, per_page } = params; const queryParams = new URLSearchParams(); if (state) queryParams.append('state', state); if (sort) queryParams.append('sort', sort); if (direction) queryParams.append('direction', direction); if (page) queryParams.append('page', page.toString()); if (per_page) queryParams.append('per_page', per_page.toString()); const query = queryParams.toString() ? `?${queryParams.toString()}` : ''; return client.get<PullRequest[]>(`/repos/${owner}/${repo}/pulls${query}`); }
  • TypeScript type definition for ListPullRequestsParams used by the listPullRequests helper function
    export interface ListPullRequestsParams { owner: string; repo: string; state?: PullRequestState; sort?: 'created' | 'updated' | 'popularity' | 'long-running'; direction?: 'asc' | 'desc'; page?: number; per_page?: number; }

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

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