add_comment
Add comments to Jira issues to provide updates, share information, or document progress on tasks and projects.
Instructions
Add a comment to a specified Jira issue
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| issueKey | Yes | The issue key (e.g., "PROJ-123") | |
| commentBody | Yes | The comment text to add |
Implementation Reference
- src/index.ts:137-163 (handler)MCP tool handler for "add_comment" that validates inputs, calls the addComment helper from jira-client, handles errors, and returns structured output.async ({ issueKey, commentBody }) => { try { if (!issueKey || !issueKey.trim()) { throw new Error('issueKey is required'); } if (!commentBody || !commentBody.trim()) { throw new Error('commentBody is required'); } const result = await addComment(issueKey, commentBody); const output = { success: true, commentId: result.id, created: result.created, }; return { content: [{ type: 'text', text: JSON.stringify(output, null, 2) }], structuredContent: output, }; } catch (error) { const output = { success: false, ...formatError(error) }; return { content: [{ type: 'text', text: JSON.stringify(output, null, 2) }], structuredContent: output, isError: true, }; }
- src/index.ts:120-136 (schema)Zod schema definitions for input (issueKey, commentBody) and output (success, commentId, created, error) of the "add_comment" tool.title: 'Add Comment', description: 'Add a comment to a specified Jira issue', inputSchema: { issueKey: z.string().describe('The issue key (e.g., "PROJ-123")'), commentBody: z.string().describe('The comment text to add'), }, outputSchema: { success: z.boolean(), commentId: z.string().optional(), created: z.string().optional(), error: z.object({ message: z.string(), statusCode: z.number().optional(), details: z.unknown().optional(), }).optional(), }, },
- src/index.ts:117-165 (registration)Registration of the "add_comment" MCP tool with McpServer, including name, schema, and handler reference.server.registerTool( 'add_comment', { title: 'Add Comment', description: 'Add a comment to a specified Jira issue', inputSchema: { issueKey: z.string().describe('The issue key (e.g., "PROJ-123")'), commentBody: z.string().describe('The comment text to add'), }, outputSchema: { success: z.boolean(), commentId: z.string().optional(), created: z.string().optional(), error: z.object({ message: z.string(), statusCode: z.number().optional(), details: z.unknown().optional(), }).optional(), }, }, async ({ issueKey, commentBody }) => { try { if (!issueKey || !issueKey.trim()) { throw new Error('issueKey is required'); } if (!commentBody || !commentBody.trim()) { throw new Error('commentBody is required'); } const result = await addComment(issueKey, commentBody); const output = { success: true, commentId: result.id, created: result.created, }; return { content: [{ type: 'text', text: JSON.stringify(output, null, 2) }], structuredContent: output, }; } catch (error) { const output = { success: false, ...formatError(error) }; return { content: [{ type: 'text', text: JSON.stringify(output, null, 2) }], structuredContent: output, isError: true, }; } } );
- src/jira-client.ts:369-398 (helper)Supporting helper function that performs the actual Jira REST API POST request to /issue/{issueKey}/comment, converting plain text commentBody to ADF format and returning the new comment ID and creation timestamp.export async function addComment(issueKey: string, commentBody: string): Promise<{ id: string; created: string }> { const response = await jiraFetch<{ id: string; created: string; }>(`/issue/${issueKey}/comment`, { method: 'POST', body: JSON.stringify({ body: { type: 'doc', version: 1, content: [ { type: 'paragraph', content: [ { type: 'text', text: commentBody, }, ], }, ], }, }), }); return { id: response.id, created: response.created, }; }