create_comment
Add a comment to a Jira issue with plain text or Markdown formatting. Mentions users with @[accountId:displayName] and optionally restrict visibility to roles or groups.
Instructions
Add a comment to a Jira issue. Supports plain text or Markdown for rich formatting (headings, lists, code blocks, links, etc.). Markdown is automatically converted to ADF. For mentions, use format: @[accountId:displayName] (get accountId from get_users tool). Returns comment ID and creation details.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| issueKey | Yes | Issue key (e.g., "PROJ-123") to add the comment to. | |
| body | Yes | Comment content. Can be plain text or Markdown for rich formatting (headings, lists, code blocks, links, etc.). Markdown will be automatically converted to ADF. For mentions, use format: @[accountId:displayName] (get accountId from get_users tool). | |
| visibility | No | Optional visibility settings to restrict comment access to specific roles or groups. |
Implementation Reference
- src/index.ts:44-44 (registration)Tool 'create_comment' is registered via createCommentTools() which returns a Tool object with name 'create_comment'. The tools list is served through the ListToolsRequestSchema handler.
const commentTools = createCommentTools(this.jiraClient); - src/index.ts:79-84 (registration)Routing: when CallToolRequestSchema receives a tool call with name starting with 'create_comment', it routes to handleCommentTool().
name.startsWith('create_comment') || name.startsWith('get_comments') || name.startsWith('update_comment') || name.startsWith('delete_comment') ) { return await handleCommentTool(name, args || {}, this.jiraClient); - src/tools/comments.ts:137-148 (handler)Handler for 'create_comment': validates args via createCommentSchema, calls jiraClient.createComment(), returns success message with comment ID.
case 'create_comment': { const validatedArgs = createCommentSchema.cast(args); const comment = await jiraClient.createComment(validatedArgs); return { content: [ { type: 'text', text: `Comment ${comment.id} created successfully`, }, ], }; } - src/schemas/index.ts:54-87 (schema)Yup validation schema for create_comment: requires issueKey (string) and body (string that gets transformed to ADF format), optional visibility object.
export const createCommentSchema = yup.object({ issueKey: yup.string().required('Issue key is required'), body: yup.mixed() .required('Comment body is required') .test('is-string', 'Body must be a string', function (value) { return typeof value === 'string'; }) .transform(function (value) { // If it's a string and looks like markdown, convert to ADF if (typeof value === 'string' && isMarkdown(value)) { return markdownToADF(value); } // For plain text, create a simple ADF paragraph return { version: 1, type: 'doc', content: [ { type: 'paragraph', content: [ { type: 'text', text: value } ] } ] }; }), visibility: yup.object({ type: yup.string().oneOf(['role', 'group']).optional(), value: yup.string().optional(), }).optional().default(undefined), }); - src/jira-client.ts:329-356 (helper)JiraClient.createComment() method: calls jira.issueComments.addComment() with the issueKey, ADF body, and optional visibility. Returns the API response.
async createComment(input: CreateCommentInput) { try { // The schema now handles the conversion from string to ADF // So input.body is already an ADF object const adfBody = input.body as AddComment['comment']; const response = await this.jira.issueComments.addComment({ issueIdOrKey: input.issueKey, visibility: input.visibility, comment: adfBody }); return response; } catch (error: unknown) { const errorDetails = { message: (error as Error).message, status: (error as JiraError).status, statusText: (error as JiraError).statusText, response: (error as JiraError).response?.data, request: { issueKey: input.issueKey, body: input.body, visibility: input.visibility } }; console.error('Comment creation error details:', JSON.stringify(errorDetails, null, 2)); throw new Error(`Failed to create comment: ${JSON.stringify(errorDetails, null, 2)}`); } }