list_pull_requests
Retrieve and filter pull requests from a GitHub repository by owner, repo, state, head, base, sort, direction, and pagination for streamlined PR management.
Instructions
List and filter repository pull requests
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base | No | Filter by base branch name | |
| direction | No | The direction of the sort | |
| head | No | Filter by head user or head organization and branch name | |
| owner | Yes | Repository owner (username or organization) | |
| page | No | Page number of the results | |
| per_page | No | Results per page (max 100) | |
| repo | Yes | Repository name | |
| sort | No | What to sort results by | |
| state | No | State of the pull requests to return |
Implementation Reference
- operations/pulls.ts:190-207 (handler)Core handler function that constructs the GitHub API URL for listing pull requests with optional filters and fetches/parses the response.export async function listPullRequests( owner: string, repo: string, options: Omit<z.infer<typeof ListPullRequestsSchema>, 'owner' | 'repo'> ): Promise<z.infer<typeof GitHubPullRequestSchema>[]> { const url = new URL(`https://api.github.com/repos/${owner}/${repo}/pulls`); if (options.state) url.searchParams.append('state', options.state); if (options.head) url.searchParams.append('head', options.head); if (options.base) url.searchParams.append('base', options.base); if (options.sort) url.searchParams.append('sort', options.sort); if (options.direction) url.searchParams.append('direction', options.direction); if (options.per_page) url.searchParams.append('per_page', options.per_page.toString()); if (options.page) url.searchParams.append('page', options.page.toString()); const response = await githubRequest(url.toString()); return z.array(GitHubPullRequestSchema).parse(response); }
- operations/pulls.ts:96-106 (schema)Zod input schema defining parameters for the list_pull_requests tool, including owner, repo, and optional filters.export const ListPullRequestsSchema = z.object({ owner: z.string().describe("Repository owner (username or organization)"), repo: z.string().describe("Repository name"), state: z.enum(['open', 'closed', 'all']).optional().describe("State of the pull requests to return"), head: z.string().optional().describe("Filter by head user or head organization and branch name"), base: z.string().optional().describe("Filter by base branch name"), sort: z.enum(['created', 'updated', 'popularity', 'long-running']).optional().describe("What to sort results by"), direction: z.enum(['asc', 'desc']).optional().describe("The direction of the sort"), per_page: z.number().optional().describe("Results per page (max 100)"), page: z.number().optional().describe("Page number of the results") });
- index.ts:160-164 (registration)Registration of the list_pull_requests tool in the ListToolsRequest handler, specifying name, description, and input schema.{ name: "list_pull_requests", description: "List and filter repository pull requests", inputSchema: zodToJsonSchema(pulls.ListPullRequestsSchema) },
- index.ts:506-513 (handler)Dispatcher handler in the main CallToolRequest switch that parses arguments, calls the listPullRequests function, and formats the response.case "list_pull_requests": { const args = pulls.ListPullRequestsSchema.parse(request.params.arguments); const { owner, repo, ...options } = args; const pullRequests = await pulls.listPullRequests(owner, repo, options); return { content: [{ type: "text", text: JSON.stringify(pullRequests, null, 2) }], }; }