add_issue_comment
Add a comment to a GitHub issue by specifying owner, repo, issue number, and comment body.
Instructions
Add a comment to 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 to comment on | |
| body | Yes | Comment content |
Implementation Reference
- src/tools/issues.ts:45-73 (handler)The handler function for the 'add_issue_comment' MCP tool. Calls `octokit.rest.issues.createComment` to add a comment to a GitHub issue. Takes owner, repo, issue_number, and body as input, and returns the comment URL and ID on success.
// Tool: Add Issue Comment server.tool( "add_issue_comment", "Add a comment to 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 to comment on"), body: z.string().describe("Comment content"), }, async ({ owner, repo, issue_number, body }) => { try { const response = await octokit.rest.issues.createComment({ owner, repo, issue_number, body, }) const c = response.data return { content: [{ type: "text", text: `Comment added to #${issue_number}\nURL: ${c.html_url}\nID: ${c.id}` }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, ) - src/tools/issues.ts:49-54 (schema)Input schema for 'add_issue_comment' defining required parameters: owner (string), repo (string), issue_number (number), and body (string), each with Zod validation and descriptions.
{ owner: z.string().describe("Repository owner"), repo: z.string().describe("Repository name"), issue_number: z.number().describe("Issue number to comment on"), body: z.string().describe("Comment content"), }, - src/tools/issues.ts:46-73 (registration)Registration of the tool via `server.tool("add_issue_comment", ...)` within the `registerIssueTools` function.
server.tool( "add_issue_comment", "Add a comment to 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 to comment on"), body: z.string().describe("Comment content"), }, async ({ owner, repo, issue_number, body }) => { try { const response = await octokit.rest.issues.createComment({ owner, repo, issue_number, body, }) const c = response.data return { content: [{ type: "text", text: `Comment added to #${issue_number}\nURL: ${c.html_url}\nID: ${c.id}` }], } } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.message}` }], } } }, ) - src/index.ts:14-16 (registration)The `registerAllToolsAndResources` function calls `registerIssueTools(server, octokit)` which registers all issue tools including 'add_issue_comment'.
export function registerAllToolsAndResources(server: McpServer, octokit: Octokit): void { registerSearchTools(server, octokit) registerIssueTools(server, octokit)