Skip to main content
Glama

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
NameRequiredDescriptionDefault
baseNoFilter by base branch name
directionNoThe direction of the sort
headNoFilter by head user or head organization and branch name
ownerYesRepository owner (username or organization)
pageNoPage number of the results
per_pageNoResults per page (max 100)
repoYesRepository name
sortNoWhat to sort results by
stateNoState of the pull requests to return

Implementation Reference

  • 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); }
  • 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) },
  • 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) }], }; }

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

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