Skip to content

Add get_prs_reviewed_by tool for direct review lookup#1971

Open
brettfire wants to merge 2 commits intogithub:mainfrom
brettfire:feat/get-prs-reviewed-by
Open

Add get_prs_reviewed_by tool for direct review lookup#1971
brettfire wants to merge 2 commits intogithub:mainfrom
brettfire:feat/get-prs-reviewed-by

Conversation

@brettfire
Copy link

@brettfire brettfire commented Feb 9, 2026

Summary

This PR addresses a (seemingly bug?) I've encountered with the github API when searching for PR data for specific users, using two patches. I apologize if this is actually caused by some issue on my end, but it may also be a legitimate bug in the github search functionality. Many users seem to state that the search functionality is pretty broken, so I'm not discounting the possibility that this is a bug. Experience has shown that github doesn't necessarily address user requests in a reasonable amount of time, so I came up with some workarounds here.

I'll also say that due to the stochastic nature of LLMs, I really can't say that the hints/instructions in the tool defs will result in entirely reliable steering. I can say that they did in my extremely limited testing, but YMMV. I'm also entirely okay with keeping this as my own private fork if the community feels that this patch is unnecessary to the userbase.

Add get_prs_reviewed_by

Add new get_prs_reviewed_by tool that finds PRs reviewed by a specific user using direct API calls instead of the Search API.
This is a workaround for when reviewed-by: qualifier doesn't work for some user accounts.

Problem

The GitHub Search API reviewed-by: qualifier returns 422 errors for some user accounts:

gh api "search/issues?q=reviewed-by:mysteryuser+is:pr"

{
  "message": "Validation Failed",
  "errors": [
    {
      "message": "The listed users cannot be searched either because the users do not exist or you do not have permission to view the users.",
      "resource": "Search",
      "field": "q",
      "code": "invalid"
    }
  ],
  "documentation_url": "https://docs.github.com/v3/search/",
  "status": "422"
}
gh: Validation Failed (HTTP 422)

While I can't find a direct reference to this (seemingly) bug elsewhere, I can confirm that the standard search endpoint fails to discover a user in my org, while listing pull requests and filtering does the trick.

Solution

  1. List PRs using client.PullRequests.List()
  2. For each PR, run client.PullRequests.ListReviews()
  3. Filters PRs where any review author matches the requested reviewer

Downsides are that the owner and repo must be specified. I've updated the tool help for some of the other related tools that fail in this situation so that the LLM agent using the MCP server will hopefully guide itself to trying this tool alternatively if it receives a 422 error. I apologize if this is not proper, but it did work well in limited testing for me (as can be seen in test plan).

Test Plan

Using claude code:

  1. Find a user that does not work with reviewer retrieval using standard search. I have one in my org, but due to privacy reasons, you'll have to find your own or trust me ;-)
  2. Ask the agent to find PRs reviewed by the user:
❯ find prs reviewed by mysteryuser in github

⏺ github - Search pull requests (MCP)(query: "reviewed-by:mysteryuser", sort: "updated", order: "desc", perPage: 10)
  ⎿  Error: failed to search pull requests: GET https://api.github.com/search/issues?order=desc&page=1&per_page=10&q=is%3Apr+reviewed-by%3Amysteryuser&sort=updated:
     422 Validation Failed [{Resource:Search Field:q Code:invalid Message:The listed users cannot be searched either because the users do not exist or you do
     not have permission to view the users.}]


⏺ github - Search users (MCP)(query: "mysteryuser")
  ⎿  {
       "total_count": 3,
       "incomplete_results": false,
     … +21 lines (ctrl+o to expand)

⏺ The user "mysteryuser" exists on GitHub (https://github.com/mysteryuser), but the GitHub API returned a 422 error when searching for PRs they reviewed. This typically
  happens when:

  1. The user hasn't reviewed any public PRs
  2. API limitations on the reviewed-by: search qualifier

  The get_prs_reviewed_by tool requires specifying a particular repository. Do you have a specific repository in mind where you'd like to search for mysteryuser's
  reviews? If so, provide the owner/repo and I can search there directly.

✻ Brewed for 33s

❯ yes use myorg owner, ai-lab repo

⏺ github-local - Get PRs reviewed by user (MCP)(owner: "myorg", repo: "ai-lab", reviewer: "mysteryuser", state: "all", perPage: 20)
  ⎿  {
       "pull_requests": [
         {
     … +34 lines (ctrl+o to expand)

⏺ Found 4 PRs reviewed by mysteryuser in myorg/ai-lab:

┌──────────────────────────────────────────────────────┬─────────────────────────────────────────────┬────────────┬────────┐
│ #                                                    │ Title                                       │ Author     │ State  │
├──────────────────────────────────────────────────────┼─────────────────────────────────────────────┼────────────┼────────┤
│ https://github.com/myorg/ai-lab/pull/4               │ added ceph storage for data pipeline        │ xxxxxxx    │ closed │
│ https://github.com/myorg/ai-lab/pull/3               │ Sglang fix                                  │ xxxxxxxxxx │ closed │
│ https://github.com/myorg/ai-lab/pull/2               │ Fix sglang deployment                       │ xxxxxxxxxx │ closed │
│ https://github.com/myorg/ai-lab/pull/1               │ Testing SGLang deployment of GPT-OSS-120B   │ xxxxxxxxxx │ closed │
└──────────────────────────────────────────────────────┴─────────────────────────────────────────────┴────────────┴────────┘


  All PRs are closed. Would you like more details on any of these?

Modify list_pull_requests tool to add local/client side author filtering

Modify the list_pull_requests tool to add client side author filtering.
This is a workaround for when querying PRs for a specific user using the search endpoint fails.

Problem

The GitHub Search API /issues?q=author endpoint returns 422 errors for some user accounts:

gh api "search/issues?q=author:mysteryuser+repo:myorg/ai-lab+is:pr"

{
  "message": "Validation Failed",
  "errors": [
    {
      "message": "The listed users cannot be searched either because the users do not exist or you do not have permission to view the users.",
      "resource": "Search",
      "field": "q",
      "code": "invalid"
    }
  ],
  "documentation_url": "https://docs.github.com/v3/search/",
  "status": "422"
}
gh: Validation Failed (HTTP 422)

This involves the same search endpoint that returns the 422 error from part one of this PR.

Solution

  1. Filter the list of PRs locally/on the client side by author.

Downsides are that filtering on the client side may introduce some minor amount of latency. I have not benchmarked this but it's likely minor.

@brettfire brettfire force-pushed the feat/get-prs-reviewed-by branch from 3da1dd9 to 72b6dc8 Compare February 9, 2026 08:22
@brettfire brettfire marked this pull request as ready for review February 9, 2026 08:26
@brettfire brettfire requested a review from a team as a code owner February 9, 2026 08:26
mcp.Tool{
Name: "list_pull_requests",
Description: t("TOOL_LIST_PULL_REQUESTS_DESCRIPTION", "List pull requests in a GitHub repository. If the user specifies an author, then DO NOT use this tool and use the search_pull_requests tool instead."),
Description: t("TOOL_LIST_PULL_REQUESTS_DESCRIPTION", "List pull requests in a GitHub repository. If the user specifies an author, then DO NOT use this tool and use the search_pull_requests tool instead. If you receive a 422 error from search_pull_requests, then use the get_prs_reviewed_by tool (to list by reviewer), or this tool with the author parameter (for filtering by author) depending on what you need."),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description for TOOL_LIST_PULL_REQUESTS_DESCRIPTION is getting a bit long and complex. Consider rephrasing for clarity or splitting it into multiple sentences.

}
}
prs = filtered
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comments for the new function GetPRsReviewedBy to explain the high-level logic.

assert.Contains(t, schema.Properties, "owner")
assert.Contains(t, schema.Properties, "repo")
assert.Contains(t, schema.Properties, "reviewer")
assert.Contains(t, schema.Properties, "state")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments to explain what the different mock reviews represent, this will help future maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants