Add tool to list existing PR reviews

This commit is contained in:
Justin Spahr-Summers
2025-01-10 13:53:13 +00:00
parent a47abf5cce
commit 6ec4dff99a
3 changed files with 67 additions and 0 deletions

View File

@@ -269,6 +269,14 @@ MCP Server for the GitHub API, enabling file operations, repository management,
- `pull_number` (number): Pull request number
- Returns: Array of pull request review comments with details like the comment text, author, and location in the diff
26. `get_pull_request_reviews`
- Get the reviews on a pull request
- Inputs:
- `owner` (string): Repository owner
- `repo` (string): Repository name
- `pull_number` (number): Pull request number
- Returns: Array of pull request reviews with details like the review state (APPROVED, CHANGES_REQUESTED, etc.), reviewer, and review body
## Search Query Syntax
### Code Search

View File

@@ -56,6 +56,8 @@ import {
UpdateIssueOptionsSchema,
GetPullRequestCommentsSchema,
PullRequestCommentSchema,
GetPullRequestReviewsSchema,
PullRequestReviewSchema,
type FileOperation,
type GitHubCommit,
type GitHubContent,
@@ -904,6 +906,29 @@ async function getPullRequestComments(
return z.array(PullRequestCommentSchema).parse(await response.json());
}
async function getPullRequestReviews(
owner: string,
repo: string,
pullNumber: number
): Promise<z.infer<typeof PullRequestReviewSchema>[]> {
const response = await fetch(
`https://api.github.com/repos/${owner}/${repo}/pulls/${pullNumber}/reviews`,
{
headers: {
Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`,
Accept: "application/vnd.github.v3+json",
"User-Agent": "github-mcp-server",
},
}
);
if (!response.ok) {
throw new Error(`GitHub API error: ${response.statusText}`);
}
return z.array(PullRequestReviewSchema).parse(await response.json());
}
async function getPullRequestStatus(
owner: string,
repo: string,
@@ -1078,6 +1103,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
name: "get_pull_request_comments",
description: "Get the review comments on a pull request",
inputSchema: zodToJsonSchema(GetPullRequestCommentsSchema)
},
{
name: "get_pull_request_reviews",
description: "Get the reviews on a pull request",
inputSchema: zodToJsonSchema(GetPullRequestReviewsSchema)
}
],
};
@@ -1334,6 +1364,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
return { content: [{ type: "text", text: JSON.stringify(comments, null, 2) }] };
}
case "get_pull_request_reviews": {
const args = GetPullRequestReviewsSchema.parse(request.params.arguments);
const reviews = await getPullRequestReviews(args.owner, args.repo, args.pull_number);
return { content: [{ type: "text", text: JSON.stringify(reviews, null, 2) }] };
}
default:
throw new Error(`Unknown tool: ${request.params.name}`);
}

View File

@@ -856,3 +856,26 @@ export type CombinedStatus = z.infer<typeof CombinedStatusSchema>;
export type UpdatePullRequestBranch = z.infer<typeof UpdatePullRequestBranchSchema>;
export type GetPullRequestComments = z.infer<typeof GetPullRequestCommentsSchema>;
export type PullRequestComment = z.infer<typeof PullRequestCommentSchema>;
// Schema for listing PR reviews
export const GetPullRequestReviewsSchema = z.object({
owner: z.string().describe("Repository owner (username or organization)"),
repo: z.string().describe("Repository name"),
pull_number: z.number().describe("Pull request number")
});
export const PullRequestReviewSchema = z.object({
id: z.number(),
node_id: z.string(),
user: GitHubIssueAssigneeSchema,
body: z.string().nullable(),
state: z.enum(['APPROVED', 'CHANGES_REQUESTED', 'COMMENTED', 'DISMISSED', 'PENDING']),
html_url: z.string(),
pull_request_url: z.string(),
commit_id: z.string(),
submitted_at: z.string().nullable(),
author_association: z.string()
});
export type GetPullRequestReviews = z.infer<typeof GetPullRequestReviewsSchema>;
export type PullRequestReview = z.infer<typeof PullRequestReviewSchema>;