get_issue_comments
Retrieve comments for a specific GitHub issue by providing repository owner, name, and issue number, with optional pagination.
Instructions
Get comments for a specific issue in a GitHub repository.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner | |
| repo | Yes | Repository name | |
| issue_number | Yes | Issue number | |
| page | No | Page number | |
| per_page | No | Number of records per page |
Implementation Reference
- src/tools/issues.ts:393-438 (handler)Handler/implementation for get_issue_comments tool. Calls octokit.rest.issues.listComments with owner, repo, issue_number, page, per_page parameters, formats results as markdown, and handles empty results and errors.
async ({ owner, repo, issue_number, page, per_page }) => { try { const response = await octokit.rest.issues.listComments({ owner, repo, issue_number, page, per_page, }) // Format the response as clean markdown const comments = response.data if (comments.length === 0) { return { content: [ { type: "text", text: "No comments found for this issue." }, ], } } let markdown = `# Comments for Issue #${issue_number}\n\n` markdown += `Showing ${comments.length} comment(s) - Page ${page}\n` if (comments.length === per_page) { markdown += `*Note: More comments may be available. Use 'page' parameter to see next page.*\n` } markdown += `\n` comments.forEach((comment, index) => { markdown += `## Comment ${index + 1}\n\n` markdown += `- **Author**: ${comment.user?.login || "Unknown"}\n` markdown += `- **Created**: ${new Date(comment.created_at).toLocaleDateString()}\n` markdown += `- **Updated**: ${new Date(comment.updated_at).toLocaleDateString()}\n\n` markdown += `**Content**:\n${comment.body}\n\n` markdown += `---\n\n` }) return { content: [{ type: "text", text: markdown }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, - src/tools/issues.ts:382-391 (schema)Input schema for get_issue_comments tool using Zod validation: owner (string), repo (string), issue_number (number), page (number, optional, default 1), per_page (number, optional, default 10).
{ owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), issue_number: z.number().describe("Issue number"), page: z.number().optional().default(1).describe("Page number"), per_page: z .number() .optional() .default(10) .describe("Number of records per page"), - src/tools/issues.ts:378-439 (registration)Registration of 'get_issue_comments' tool via server.tool() call with name, description, schema, and handler. Contained within the registerIssueTools function.
// Tool: Get Issue Comments server.tool( "get_issue_comments", "Get comments for a specific issue in a GitHub repository.", { owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), issue_number: z.number().describe("Issue number"), page: z.number().optional().default(1).describe("Page number"), per_page: z .number() .optional() .default(10) .describe("Number of records per page"), }, async ({ owner, repo, issue_number, page, per_page }) => { try { const response = await octokit.rest.issues.listComments({ owner, repo, issue_number, page, per_page, }) // Format the response as clean markdown const comments = response.data if (comments.length === 0) { return { content: [ { type: "text", text: "No comments found for this issue." }, ], } } let markdown = `# Comments for Issue #${issue_number}\n\n` markdown += `Showing ${comments.length} comment(s) - Page ${page}\n` if (comments.length === per_page) { markdown += `*Note: More comments may be available. Use 'page' parameter to see next page.*\n` } markdown += `\n` comments.forEach((comment, index) => { markdown += `## Comment ${index + 1}\n\n` markdown += `- **Author**: ${comment.user?.login || "Unknown"}\n` markdown += `- **Created**: ${new Date(comment.created_at).toLocaleDateString()}\n` markdown += `- **Updated**: ${new Date(comment.updated_at).toLocaleDateString()}\n\n` markdown += `**Content**:\n${comment.body}\n\n` markdown += `---\n\n` }) return { content: [{ type: "text", text: markdown }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, ) - src/tools/issues.ts:5-5 (registration)Parent function registerIssueTools that wraps all issue tool registrations (including get_issue_comments). Called from src/index.ts line 16.
export function registerIssueTools(server: McpServer, octokit: Octokit) {