Skip to content

Commit 6ec4dff

Browse files
committed
Add tool to list existing PR reviews
1 parent a47abf5 commit 6ec4dff

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/github/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ MCP Server for the GitHub API, enabling file operations, repository management,
269269
- `pull_number` (number): Pull request number
270270
- Returns: Array of pull request review comments with details like the comment text, author, and location in the diff
271271

272+
26. `get_pull_request_reviews`
273+
- Get the reviews on a pull request
274+
- Inputs:
275+
- `owner` (string): Repository owner
276+
- `repo` (string): Repository name
277+
- `pull_number` (number): Pull request number
278+
- Returns: Array of pull request reviews with details like the review state (APPROVED, CHANGES_REQUESTED, etc.), reviewer, and review body
279+
272280
## Search Query Syntax
273281

274282
### Code Search

src/github/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import {
5656
UpdateIssueOptionsSchema,
5757
GetPullRequestCommentsSchema,
5858
PullRequestCommentSchema,
59+
GetPullRequestReviewsSchema,
60+
PullRequestReviewSchema,
5961
type FileOperation,
6062
type GitHubCommit,
6163
type GitHubContent,
@@ -904,6 +906,29 @@ async function getPullRequestComments(
904906
return z.array(PullRequestCommentSchema).parse(await response.json());
905907
}
906908

909+
async function getPullRequestReviews(
910+
owner: string,
911+
repo: string,
912+
pullNumber: number
913+
): Promise<z.infer<typeof PullRequestReviewSchema>[]> {
914+
const response = await fetch(
915+
`https://api.github.com/repos/${owner}/${repo}/pulls/${pullNumber}/reviews`,
916+
{
917+
headers: {
918+
Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`,
919+
Accept: "application/vnd.github.v3+json",
920+
"User-Agent": "github-mcp-server",
921+
},
922+
}
923+
);
924+
925+
if (!response.ok) {
926+
throw new Error(`GitHub API error: ${response.statusText}`);
927+
}
928+
929+
return z.array(PullRequestReviewSchema).parse(await response.json());
930+
}
931+
907932
async function getPullRequestStatus(
908933
owner: string,
909934
repo: string,
@@ -1078,6 +1103,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
10781103
name: "get_pull_request_comments",
10791104
description: "Get the review comments on a pull request",
10801105
inputSchema: zodToJsonSchema(GetPullRequestCommentsSchema)
1106+
},
1107+
{
1108+
name: "get_pull_request_reviews",
1109+
description: "Get the reviews on a pull request",
1110+
inputSchema: zodToJsonSchema(GetPullRequestReviewsSchema)
10811111
}
10821112
],
10831113
};
@@ -1334,6 +1364,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
13341364
return { content: [{ type: "text", text: JSON.stringify(comments, null, 2) }] };
13351365
}
13361366

1367+
case "get_pull_request_reviews": {
1368+
const args = GetPullRequestReviewsSchema.parse(request.params.arguments);
1369+
const reviews = await getPullRequestReviews(args.owner, args.repo, args.pull_number);
1370+
return { content: [{ type: "text", text: JSON.stringify(reviews, null, 2) }] };
1371+
}
1372+
13371373
default:
13381374
throw new Error(`Unknown tool: ${request.params.name}`);
13391375
}

src/github/schemas.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,3 +856,26 @@ export type CombinedStatus = z.infer<typeof CombinedStatusSchema>;
856856
export type UpdatePullRequestBranch = z.infer<typeof UpdatePullRequestBranchSchema>;
857857
export type GetPullRequestComments = z.infer<typeof GetPullRequestCommentsSchema>;
858858
export type PullRequestComment = z.infer<typeof PullRequestCommentSchema>;
859+
860+
// Schema for listing PR reviews
861+
export const GetPullRequestReviewsSchema = z.object({
862+
owner: z.string().describe("Repository owner (username or organization)"),
863+
repo: z.string().describe("Repository name"),
864+
pull_number: z.number().describe("Pull request number")
865+
});
866+
867+
export const PullRequestReviewSchema = z.object({
868+
id: z.number(),
869+
node_id: z.string(),
870+
user: GitHubIssueAssigneeSchema,
871+
body: z.string().nullable(),
872+
state: z.enum(['APPROVED', 'CHANGES_REQUESTED', 'COMMENTED', 'DISMISSED', 'PENDING']),
873+
html_url: z.string(),
874+
pull_request_url: z.string(),
875+
commit_id: z.string(),
876+
submitted_at: z.string().nullable(),
877+
author_association: z.string()
878+
});
879+
880+
export type GetPullRequestReviews = z.infer<typeof GetPullRequestReviewsSchema>;
881+
export type PullRequestReview = z.infer<typeof PullRequestReviewSchema>;

0 commit comments

Comments
 (0)