update_comment
Modify or remove an existing comment on a Linear issue by providing the comment ID and new content or setting the delete flag.
Instructions
A tool that updates or deletes an existing comment on an issue in Linear
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| comment | No | The new content for the comment | |
| commentId | Yes | The ID of the comment to update | |
| delete | No | Whether to delete the comment |
Implementation Reference
- The async handler function that implements the core logic of the 'update_comment' tool, including validation, update/delete operations via Linear client, error handling, and response formatting.handler: async (args: z.infer<typeof updateCommentSchema>) => { try { // Validate input if (!args.commentId || args.commentId.trim() === "") { return { content: [{ type: "text", text: "Error: Comment ID cannot be empty", }], }; } // Handle delete operation if delete flag is true if (args.delete === true) { // Delete the comment const deleteCommentResponse = await linearClient.deleteComment(args.commentId); if (!deleteCommentResponse) { return { content: [{ type: "text", text: "Failed to delete comment. Please check the comment ID and try again.", }], }; } // Check if the delete operation was successful const deleteResponse = deleteCommentResponse as unknown as LinearDeleteResponse; if (deleteResponse.success === false) { return { content: [{ type: "text", text: "Failed to delete comment. Please check the comment ID and try again.", }], }; } // Return success message for deletion return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment deleted\nComment ID: ${args.commentId}`, }], }; } // For update operations, comment content is required if (!args.comment || args.comment.trim() === "") { return { content: [{ type: "text", text: "Error: Comment content cannot be empty for update operations", }], }; } // Update the comment const updateCommentResponse = await linearClient.updateComment(args.commentId, { body: args.comment, }); if (!updateCommentResponse) { return { content: [{ type: "text", text: "Failed to update comment. Please check the comment ID and try again.", }], }; } // Mendapatkan ID komentar dari respons // Linear SDK mengembalikan hasil dalam pola success dan entity if (updateCommentResponse.success) { // Mengakses komentar dan mendapatkan ID dengan tipe data yang benar const comment = await updateCommentResponse.comment; if (comment && comment.id) { return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment updated\nComment ID: ${comment.id}`, }], }; } } // Extract data from response to check for success const commentResponse = updateCommentResponse as unknown as LinearCommentResponse; // If the response indicates failure, return an error if (commentResponse.success === false) { return { content: [{ type: "text", text: "Failed to update comment. Please check the comment ID and try again.", }], }; } // Extract comment data from the correct property const commentData: CommentResponseData = commentResponse.comment || updateCommentResponse as unknown as CommentResponseData; // Langsung cek hasil respons yang telah diparsing const commentId = commentData?.id || (updateCommentResponse as unknown as { id?: string })?.id; if (commentId) { return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment updated\nComment ID: ${commentId}`, }], }; } if (!commentData) { // Tampilkan pesan sukses meski data tidak lengkap return { content: [{ type: "text", text: "Status: Success\nMessage: Linear comment updated", }], }; } if (!commentData.id) { // Data komentar ada tapi tidak ada ID return { content: [{ type: "text", text: "Status: Success\nMessage: Linear comment updated (ID not available)", }], }; } // Kasus sukses dengan ID tersedia return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment updated\nComment ID: ${commentData.id}`, }], }; } catch (error) { // Handle errors gracefully const errorMessage = error instanceof Error ? error.message : "Unknown error"; return { content: [{ type: "text", text: `An error occurred while updating or deleting the comment:\n${errorMessage}`, }], }; } }
- Zod schema defining the input schema for the 'update_comment' tool: commentId (required), comment (optional for update), delete (optional boolean).const updateCommentSchema = z.object({ commentId: z.string().describe("The ID of the comment to update"), comment: z.string().describe("The new content for the comment").optional(), delete: z.boolean().describe("Whether to delete the comment").optional().default(false), });
- src/index.ts:31-41 (registration)Registration of the LinearUpdateCommentTool (which has name: 'update_comment') along with other tools in the MCP server using registerTool.registerTool(server, [ LinearSearchIssuesTool, LinearGetProfileTool, LinearCreateIssueTool, LinearCreateCommentTool, LinearUpdateCommentTool, LinearGetIssueTool, LinearGetTeamIdTool, LinearUpdateIssueTool, LinearGetCommentTool, ]);
- src/tools/linear/tools.ts:12-18 (registration)Re-export of LinearUpdateCommentTool from its implementation file, making it available for import in src/index.ts.export { LinearGetProfileTool, LinearSearchIssuesTool, LinearCreateIssueTool, LinearUpdateIssueTool, LinearCreateCommentTool, LinearUpdateCommentTool,