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
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner (user or organization) | |
| repo | Yes | Repository name | |
| state | No | PR state filter | open |
| sort | No | Sort criteria | created |
| direction | No | Sort direction | desc |
| page | No | Page number | |
| per_page | No | Items per page |
Implementation Reference
- server/index.ts:520-521 (registration)Registration of the MCP tool named 'list-pull-requests'server.tool( "list-pull-requests",
- server/index.ts:522-530 (schema)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") },
- server/index.ts:531-614 (handler)Handler function for 'list-pull-requests' tool: validates input, calls GitHub API via helper, formats and returns PR list or errorasync ({ 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 }; } } );
- api/pulls/pulls.ts:22-38 (helper)Helper function implementing the GitHub API call to list pull requests for a repositoryexport 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}`); }
- api/pulls/types.ts:53-61 (schema)TypeScript type definition for ListPullRequestsParams used by the listPullRequests helper functionexport interface ListPullRequestsParams { owner: string; repo: string; state?: PullRequestState; sort?: 'created' | 'updated' | 'popularity' | 'long-running'; direction?: 'asc' | 'desc'; page?: number; per_page?: number; }