list-pull-requests
List pull requests for a GitHub Enterprise repository by applying filters like state, sort criteria, and direction. Retrieve PRs in a structured format for better workflow management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | No | Sort direction | desc |
| owner | Yes | Repository owner (user or organization) | |
| page | No | Page number | |
| per_page | No | Items per page | |
| repo | Yes | Repository name | |
| sort | No | Sort criteria | created |
| state | No | PR state filter | open |
Implementation Reference
- server/index.ts:520-614 (handler)Primary MCP tool handler for 'list-pull-requests': validates input with Zod schema, calls the underlying API helper, formats results, handles errors, and returns structured content.server.tool( "list-pull-requests", { 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") }, 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 }; } } );
- server/index.ts:520-520 (registration)Registration of the 'list-pull-requests' tool using McpServer.tool() method.server.tool(
- server/index.ts:522-530 (schema)Input schema for 'list-pull-requests' tool defined using Zod validation.{ 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") },
- api/pulls/pulls.ts:22-38 (helper)Underlying GitHub API helper function listPullRequests that performs the actual HTTP request to list pull requests.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}`); }
- api/pulls/types.ts:53-61 (schema)TypeScript interface ListPullRequestsParams used by the 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; }