list-pull-requests
Retrieve and filter pull requests from GitHub repositories by state, branch, or sorting criteria to monitor code review activity and manage contributions.
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
- src/tools/pull-requests.ts:20-80 (handler)The handler function for 'list-pull-requests' tool. Validates input with ListPullRequestsSchema, fetches pull requests via GitHub API, and returns formatted list.export async function listPullRequests(args: unknown): Promise<any> { const { owner, repo, state, head, base, sort, direction, per_page, page } = ListPullRequestsSchema.parse(args); const github = getGitHubApi(); return tryCatchAsync(async () => { const { data } = await github.getOctokit().pulls.list({ owner, repo, state, head, base, sort, direction, per_page, page, }); return data.map((pr) => ({ id: pr.id, number: pr.number, title: pr.title, state: pr.state, locked: pr.locked, user: pr.user ? { login: pr.user.login, id: pr.user.id, type: pr.user.type, } : null, created_at: pr.created_at, updated_at: pr.updated_at, closed_at: pr.closed_at, merged_at: pr.merged_at, merge_commit_sha: pr.merge_commit_sha, draft: pr.draft, head: { ref: pr.head.ref, sha: pr.head.sha, repo: pr.head.repo ? { name: pr.head.repo.name, full_name: pr.head.repo.full_name, owner: { login: pr.head.repo.owner.login, }, } : null, }, base: { ref: pr.base.ref, sha: pr.base.sha, repo: pr.base.repo ? { name: pr.base.repo.name, full_name: pr.base.repo.full_name, owner: { login: pr.base.repo.owner.login, }, } : null, }, body: pr.body, url: pr.html_url, })); }, 'Failed to list pull requests'); }
- src/utils/validation.ts:115-123 (schema)Zod schema used for input validation in the listPullRequests handler.export const ListPullRequestsSchema = OwnerRepoSchema.extend({ state: z.enum(['open', 'closed', 'all']).optional(), head: z.string().optional(), base: z.string().optional(), sort: z.enum(['created', 'updated', 'popularity', 'long-running']).optional(), direction: z.enum(['asc', 'desc']).optional(), per_page: z.number().optional(), page: z.number().optional(), });
- src/server.ts:693-742 (registration)Tool registration in the ListToolsRequestSchema handler, defining name, description, and inputSchema.{ name: 'list-pull-requests', description: 'List and filter repository pull requests', inputSchema: { type: 'object', properties: { owner: { type: 'string', description: 'Repository owner (username or organization)', }, repo: { type: 'string', description: 'Repository name', }, state: { type: 'string', enum: ['open', 'closed', 'all'], description: 'State of the pull requests to return', }, head: { type: 'string', description: 'Filter by head user or head organization and branch name', }, base: { type: 'string', description: 'Filter by base branch name', }, sort: { type: 'string', enum: ['created', 'updated', 'popularity', 'long-running'], description: 'What to sort results by', }, direction: { type: 'string', enum: ['asc', 'desc'], description: 'The direction of the sort', }, per_page: { type: 'number', description: 'Results per page (max 100)', }, page: { type: 'number', description: 'Page number of the results', }, }, required: ['owner', 'repo'], additionalProperties: false, }, },
- src/server.ts:1226-1228 (registration)Dispatch case in CallToolRequestSchema handler that invokes the listPullRequests function.case 'list-pull-requests': result = await listPullRequests(parsedArgs); break;