mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-19 16:54:19 +02:00
Add tool to list existing PR reviews
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user