create_comment
Add comments to Linear issues to provide updates, share information, or collaborate with team members on project tasks.
Instructions
A tool that creates a comment on an issue in Linear
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| comment | Yes | The comment to send to the issue | |
| issueId | Yes | The ID of the issue to send a comment to |
Implementation Reference
- The async handler function that implements the create_comment tool logic: validates inputs, calls linearClient.createComment, handles various response formats from Linear SDK, extracts comment ID, and returns formatted success/error messages.handler: async (args: z.infer<typeof createCommentSchema>) => { try { // Validate input if (!args.issueId || args.issueId.trim() === "") { return { content: [{ type: "text", text: "Error: Issue ID cannot be empty", }], }; } if (!args.comment || args.comment.trim() === "") { return { content: [{ type: "text", text: "Error: Comment content cannot be empty", }], }; } // Create the comment const createCommentResponse = await linearClient.createComment({ body: args.comment, issueId: args.issueId, }); if (!createCommentResponse) { return { content: [{ type: "text", text: "Failed to create comment. Please check the issue ID and try again.", }], }; } // Mendapatkan ID komentar dari respons // Linear SDK mengembalikan hasil dalam pola success dan entity if (createCommentResponse.success) { // Mengakses komentar dan mendapatkan ID dengan tipe data yang benar const comment = await createCommentResponse.comment; if (comment && comment.id) { return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment created\nComment ID: ${comment.id}`, }], }; } } // Extract data from response to check for success const commentResponse = createCommentResponse as unknown as LinearCommentResponse; // If the response indicates failure, return an error if (commentResponse.success === false) { return { content: [{ type: "text", text: "Failed to create comment. Please check the issue ID and try again.", }], }; } // Extract comment data from the correct property const commentData: CommentResponseData = commentResponse.comment || createCommentResponse as unknown as CommentResponseData; // Langsung cek hasil respons yang telah diparsing const commentId = commentData?.id || (createCommentResponse as unknown as { id?: string })?.id; if (commentId) { return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment created\nComment ID: ${commentId}`, }], }; } if (!commentData) { // Tampilkan pesan sukses meski data tidak lengkap return { content: [{ type: "text", text: "Status: Success\nMessage: Linear comment created", }], }; } if (!commentData.id) { // Data komentar ada tapi tidak ada ID return { content: [{ type: "text", text: "Status: Success\nMessage: Linear comment created (ID not available)", }], }; } // Kasus sukses dengan ID tersedia return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment created\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 creating the comment:\n${errorMessage}`, }], }; } }
- Zod schema defining input parameters for the create_comment tool: issueId (string) and comment (string).const createCommentSchema = z.object({ issueId: z.string().describe("The ID of the issue to send a comment to"), comment: z.string().describe("The comment to send to the issue"), });
- src/index.ts:31-41 (registration)Registers the LinearCreateCommentTool (which has name: "create_comment") on the MCP server using registerTool.registerTool(server, [ LinearSearchIssuesTool, LinearGetProfileTool, LinearCreateIssueTool, LinearCreateCommentTool, LinearUpdateCommentTool, LinearGetIssueTool, LinearGetTeamIdTool, LinearUpdateIssueTool, LinearGetCommentTool, ]);
- src/tools/linear/tools.ts:12-17 (registration)Re-exports LinearCreateCommentTool for use in index.ts registration.export { LinearGetProfileTool, LinearSearchIssuesTool, LinearCreateIssueTool, LinearUpdateIssueTool, LinearCreateCommentTool,
- Full tool definition including name 'create_comment', schema, and handler implementation using createSafeTool.export const LinearCreateCommentTool = createSafeTool({ name: "create_comment", description: "A tool that creates a comment on an issue in Linear", schema: createCommentSchema.shape, handler: async (args: z.infer<typeof createCommentSchema>) => { try { // Validate input if (!args.issueId || args.issueId.trim() === "") { return { content: [{ type: "text", text: "Error: Issue ID cannot be empty", }], }; } if (!args.comment || args.comment.trim() === "") { return { content: [{ type: "text", text: "Error: Comment content cannot be empty", }], }; } // Create the comment const createCommentResponse = await linearClient.createComment({ body: args.comment, issueId: args.issueId, }); if (!createCommentResponse) { return { content: [{ type: "text", text: "Failed to create comment. Please check the issue ID and try again.", }], }; } // Mendapatkan ID komentar dari respons // Linear SDK mengembalikan hasil dalam pola success dan entity if (createCommentResponse.success) { // Mengakses komentar dan mendapatkan ID dengan tipe data yang benar const comment = await createCommentResponse.comment; if (comment && comment.id) { return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment created\nComment ID: ${comment.id}`, }], }; } } // Extract data from response to check for success const commentResponse = createCommentResponse as unknown as LinearCommentResponse; // If the response indicates failure, return an error if (commentResponse.success === false) { return { content: [{ type: "text", text: "Failed to create comment. Please check the issue ID and try again.", }], }; } // Extract comment data from the correct property const commentData: CommentResponseData = commentResponse.comment || createCommentResponse as unknown as CommentResponseData; // Langsung cek hasil respons yang telah diparsing const commentId = commentData?.id || (createCommentResponse as unknown as { id?: string })?.id; if (commentId) { return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment created\nComment ID: ${commentId}`, }], }; } if (!commentData) { // Tampilkan pesan sukses meski data tidak lengkap return { content: [{ type: "text", text: "Status: Success\nMessage: Linear comment created", }], }; } if (!commentData.id) { // Data komentar ada tapi tidak ada ID return { content: [{ type: "text", text: "Status: Success\nMessage: Linear comment created (ID not available)", }], }; } // Kasus sukses dengan ID tersedia return { content: [{ type: "text", text: `Status: Success\nMessage: Linear comment created\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 creating the comment:\n${errorMessage}`, }], }; } } });