Skip to content

Commit a47abf5

Browse files
committed
Add support for listing PR comments
1 parent ac7592f commit a47abf5

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/github/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ MCP Server for the GitHub API, enabling file operations, repository management,
261261
- `expected_head_sha` (optional string): The expected SHA of the pull request's HEAD ref
262262
- Returns: Success message when branch is updated
263263

264+
25. `get_pull_request_comments`
265+
- Get the review comments on a pull request
266+
- Inputs:
267+
- `owner` (string): Repository owner
268+
- `repo` (string): Repository name
269+
- `pull_number` (number): Pull request number
270+
- Returns: Array of pull request review comments with details like the comment text, author, and location in the diff
271+
264272
## Search Query Syntax
265273

266274
### Code Search

src/github/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import {
5454
SearchUsersResponseSchema,
5555
SearchUsersSchema,
5656
UpdateIssueOptionsSchema,
57+
GetPullRequestCommentsSchema,
58+
PullRequestCommentSchema,
5759
type FileOperation,
5860
type GitHubCommit,
5961
type GitHubContent,
@@ -879,6 +881,29 @@ async function updatePullRequestBranch(
879881
}
880882
}
881883

884+
async function getPullRequestComments(
885+
owner: string,
886+
repo: string,
887+
pullNumber: number
888+
): Promise<z.infer<typeof PullRequestCommentSchema>[]> {
889+
const response = await fetch(
890+
`https://api.github.com/repos/${owner}/${repo}/pulls/${pullNumber}/comments`,
891+
{
892+
headers: {
893+
Authorization: `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`,
894+
Accept: "application/vnd.github.v3+json",
895+
"User-Agent": "github-mcp-server",
896+
},
897+
}
898+
);
899+
900+
if (!response.ok) {
901+
throw new Error(`GitHub API error: ${response.statusText}`);
902+
}
903+
904+
return z.array(PullRequestCommentSchema).parse(await response.json());
905+
}
906+
882907
async function getPullRequestStatus(
883908
owner: string,
884909
repo: string,
@@ -1048,6 +1073,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
10481073
name: "update_pull_request_branch",
10491074
description: "Update a pull request branch with the latest changes from the base branch",
10501075
inputSchema: zodToJsonSchema(UpdatePullRequestBranchSchema)
1076+
},
1077+
{
1078+
name: "get_pull_request_comments",
1079+
description: "Get the review comments on a pull request",
1080+
inputSchema: zodToJsonSchema(GetPullRequestCommentsSchema)
10511081
}
10521082
],
10531083
};
@@ -1298,6 +1328,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
12981328
return { content: [{ type: "text", text: "Pull request branch updated successfully" }] };
12991329
}
13001330

1331+
case "get_pull_request_comments": {
1332+
const args = GetPullRequestCommentsSchema.parse(request.params.arguments);
1333+
const comments = await getPullRequestComments(args.owner, args.repo, args.pull_number);
1334+
return { content: [{ type: "text", text: JSON.stringify(comments, null, 2) }] };
1335+
}
1336+
13011337
default:
13021338
throw new Error(`Unknown tool: ${request.params.name}`);
13031339
}

src/github/schemas.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,5 +820,39 @@ export const UpdatePullRequestBranchSchema = z.object({
820820
expected_head_sha: z.string().optional().describe("The expected SHA of the pull request's HEAD ref")
821821
});
822822

823+
// Schema for PR comments
824+
export const GetPullRequestCommentsSchema = z.object({
825+
owner: z.string().describe("Repository owner (username or organization)"),
826+
repo: z.string().describe("Repository name"),
827+
pull_number: z.number().describe("Pull request number")
828+
});
829+
830+
export const PullRequestCommentSchema = z.object({
831+
url: z.string(),
832+
id: z.number(),
833+
node_id: z.string(),
834+
pull_request_review_id: z.number().nullable(),
835+
diff_hunk: z.string(),
836+
path: z.string().nullable(),
837+
position: z.number().nullable(),
838+
original_position: z.number().nullable(),
839+
commit_id: z.string(),
840+
original_commit_id: z.string(),
841+
user: GitHubIssueAssigneeSchema,
842+
body: z.string(),
843+
created_at: z.string(),
844+
updated_at: z.string(),
845+
html_url: z.string(),
846+
pull_request_url: z.string(),
847+
author_association: z.string(),
848+
_links: z.object({
849+
self: z.object({ href: z.string() }),
850+
html: z.object({ href: z.string() }),
851+
pull_request: z.object({ href: z.string() })
852+
})
853+
});
854+
823855
export type CombinedStatus = z.infer<typeof CombinedStatusSchema>;
824856
export type UpdatePullRequestBranch = z.infer<typeof UpdatePullRequestBranchSchema>;
857+
export type GetPullRequestComments = z.infer<typeof GetPullRequestCommentsSchema>;
858+
export type PullRequestComment = z.infer<typeof PullRequestCommentSchema>;

0 commit comments

Comments
 (0)