create_pull_request_review_comment
Post a review comment on specific lines in a pull request diff to discuss code changes.
Instructions
Create a review comment (line-by-line code comment) on a pull request.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner | |
| repo | Yes | Repository name | |
| pullNumber | Yes | Pull request number | |
| body | Yes | Comment body | |
| commit_id | Yes | SHA of the commit to comment on | |
| path | Yes | Relative path to the file being commented on | |
| line | No | Line number for single-line comment | |
| start_line | No | Start line for multi-line comment | |
| side | No | Side of diff (LEFT for deletion, RIGHT for addition) | RIGHT |
| start_side | No | Start side for multi-line comment | |
| in_reply_to | No | ID of review comment to reply to |
Implementation Reference
- src/tools/pullrequests.ts:796-797 (registration)Tool 'create_pull_request_review_comment' is registered via server.tool() in the registerPullRequestTools function.
server.tool( "create_pull_request_review_comment", - src/tools/pullrequests.ts:799-827 (schema)Input schema definition using Zod: owner, repo, pullNumber, body, commit_id, path, line, start_line, side, start_side, in_reply_to.
{ owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), pullNumber: z.number().describe("Pull request number"), body: z.string().describe("Comment body"), commit_id: z.string().describe("SHA of the commit to comment on"), path: z.string().describe("Relative path to the file being commented on"), line: z .number() .optional() .describe("Line number for single-line comment"), start_line: z .number() .optional() .describe("Start line for multi-line comment"), side: z .enum(["LEFT", "RIGHT"]) .optional() .default("RIGHT") .describe("Side of diff (LEFT for deletion, RIGHT for addition)"), start_side: z .enum(["LEFT", "RIGHT"]) .optional() .describe("Start side for multi-line comment"), in_reply_to: z .number() .optional() .describe("ID of review comment to reply to"), }, - src/tools/pullrequests.ts:828-894 (handler)Handler function that calls octokit.rest.pulls.createReviewComment and formats the response as markdown.
async ({ owner, repo, pullNumber, body, commit_id, path, line, start_line, side, start_side, in_reply_to, }) => { try { const response = await octokit.rest.pulls.createReviewComment({ owner, repo, pull_number: pullNumber, body, commit_id, path, line, start_line, side, start_side, in_reply_to, }) // Format response as clean markdown const comment = response.data let markdown = `# Review Comment Created for Pull Request #${pullNumber}\n\n` markdown += `- **Comment ID:** ${comment.id}\n` markdown += `- **Author:** ${comment.user?.login || "Unknown"}\n` markdown += `- **File:** ${comment.path}\n` if (comment.line) { markdown += `- **Line:** ${comment.line}\n` } if (comment.start_line && comment.start_line !== comment.line) { markdown += `- **Lines:** ${comment.start_line}-${comment.line}\n` } markdown += `- **Side:** ${comment.side || "RIGHT"}\n` markdown += `- **Created:** ${new Date(comment.created_at).toLocaleDateString()}\n` if (comment.commit_id) { markdown += `- **Commit:** ${comment.commit_id.substring(0, 7)}\n` } if (comment.in_reply_to_id) { markdown += `- **Reply to:** Comment #${comment.in_reply_to_id}\n` } markdown += `\n**Comment:**\n${comment.body}\n` markdown += `\n**URL:** ${comment.html_url}\n` return { content: [{ type: "text", text: markdown }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, ) - src/tools/pullrequests.ts:5-5 (helper)The function registerPullRequestTools wraps all pull request tool registrations, including this tool.
export function registerPullRequestTools(server: McpServer, octokit: Octokit) {