jira_add_comment
Add comments to Jira issues with support for markdown, plain text, or ADF format, and optional visibility restrictions for groups or roles.
Instructions
Adds a comment to an issue. Supports visibility restrictions for groups or roles. Comment format is controlled by the "format" parameter (default: markdown). Returns the created comment with author details and timestamp.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| issueKey | Yes | Issue key to add comment to | |
| body | Yes | Comment body text | |
| visibility | No | Comment visibility restrictions | |
| format | No | Comment format: "markdown" (converts Markdown to ADF), "adf" (use as-is ADF object), "plain" (converts plain text to ADF with basic formatting). Default: "markdown" | markdown |
Implementation Reference
- src/tools/add-comment.ts:57-77 (handler)The main handler function that validates input, calls the API helper to add a comment, and formats the response.
export async function handleAddComment(input: unknown): Promise<McpToolResponse> { try { const validated = validateInput(AddCommentInputSchema, input); log.info(`Adding comment to issue ${validated.issueKey}...`); const comment = await addComment( validated.issueKey, validated.body, validated.visibility, validated.format ); log.info(`Added comment to ${validated.issueKey}`); return formatCommentResponse(comment); } catch (error) { log.error('Error in handleAddComment:', error); return handleError(error); } } - src/index.ts:180-186 (registration)Tool registration in src/index.ts - maps TOOL_NAMES.ADD_COMMENT ('jira_add_comment') to addCommentTool schema and handleAddComment handler.
{ name: TOOL_NAMES.ADD_COMMENT, description: tools.addCommentTool.description!, inputSchema: AddCommentInputSchema, handler: tools.handleAddComment, annotations: { readOnlyHint: false }, }, - src/types/tools.ts:180-200 (schema)Zod validation schema defining the input shape: issueKey, body, optional visibility (type/value), and optional format (markdown/adf/plain, default 'markdown').
export const AddCommentInputSchema = z.object({ issueKey: z .string() .describe('Issue key to add comment to') .refine((v) => isValidIssueKey(v), 'Invalid issue key format'), body: z.string().min(1).describe('Comment body text'), visibility: z .object({ type: z.enum(['group', 'role']).describe('Visibility type'), value: z.string().describe('Group name or role name'), }) .optional() .describe('Comment visibility restrictions'), format: z .enum(['markdown', 'adf', 'plain']) .optional() .default('markdown') .describe( 'Comment format: "markdown" (converts Markdown to ADF), "adf" (use as-is ADF object), "plain" (converts plain text to ADF with basic formatting). Default: "markdown"' ), }); - src/utils/api-helpers.ts:555-579 (helper)API helper that converts the body to ADF format via ensureAdfDescription and POSTs to /issue/{issueKey}/comment.
export async function addComment( issueKey: string, body: string, visibility?: { type: string; value: string }, format?: 'markdown' | 'adf' | 'plain' ): Promise<JiraComment> { // Convert body to ADF format (Jira expects ADF for comments) const adfBody = ensureAdfDescription(body, format || 'markdown'); const data: any = { body: adfBody, }; if (visibility) { data.visibility = visibility; } const config: AxiosRequestConfig = { method: 'POST', url: `/issue/${issueKey}/comment`, data, }; return await makeJiraRequest<JiraComment>(config); } - src/utils/formatters.ts:332-350 (helper)Formats the API response into a user-facing text message with author, timestamp, visibility, and comment content.
export function formatCommentResponse(comment: JiraComment): McpToolResponse { const visibilityText = comment.visibility ? `\n**Visibility:** ${comment.visibility.type} - ${comment.visibility.value}` : ''; return { content: [ { type: 'text', text: `**Comment added successfully** **Author:** ${comment.author.displayName} **Created:** ${new Date(comment.created).toISOString()}${visibilityText} **Content:** ${comment.body}`, }, ], };