get_comments
Retrieve paginated comments for a Jira issue. Control page navigation with startAt and maxResults parameters.
Instructions
Get comments for a Jira issue with pagination support. Returns comments with pagination metadata to help navigate through large comment lists.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| issueKey | Yes | The issue key to get comments for (e.g., "PROJ-123") | |
| startAt | No | Starting index for pagination (0-based). Use this to get the next page of comments. Default: 0 | |
| maxResults | No | Maximum number of comments to return per page (1-100). Use smaller values for faster responses. Default: 50 |
Implementation Reference
- src/tools/comments.ts:131-225 (handler)The handleCommentTool function handles the 'get_comments' tool case (lines 150-194). It validates args via getCommentsSchema, calls jiraClient.getComments(), and formats the response with pagination metadata (total, startAt, maxResults, hasNextPage, etc.) and essential comment fields (id, author, body, visibility).
export async function handleCommentTool( name: string, args: Record<string, unknown>, jiraClient: JiraClient ) { switch (name) { case 'create_comment': { const validatedArgs = createCommentSchema.cast(args); const comment = await jiraClient.createComment(validatedArgs); return { content: [ { type: 'text', text: `Comment ${comment.id} created successfully`, }, ], }; } case 'get_comments': { const validatedArgs = await getCommentsSchema.validate(args); const comments = await jiraClient.getComments(validatedArgs); // Extract essential fields with improved pagination info const commentsData = comments; const total = commentsData.total || 0; const startAt = commentsData.startAt || 0; const maxResults = commentsData.maxResults || 50; const essentialComments = { pagination: { total, startAt, maxResults, hasNextPage: (startAt + maxResults) < total, hasPreviousPage: startAt > 0, nextStartAt: (startAt + maxResults) < total ? startAt + maxResults : null, previousStartAt: startAt > 0 ? Math.max(0, startAt - maxResults) : null, }, items: commentsData.comments?.map((comment) => ({ id: comment.id, author: comment.author?.displayName, authorId: comment.author?.accountId, created: comment.created, updated: comment.updated, body: comment.body, // Return full body content (ADF format) text: comment.body?.content?.[0]?.content?.[0]?.text || '', // Extract text content for backward compatibility visibility: comment.visibility?.type || 'public' })) || [] }; return { content: [ { type: 'text', text: JSON.stringify(essentialComments, null, 2), }, ], }; } case 'update_comment': { const validatedArgs = updateCommentSchema.cast(args); const result = await jiraClient.updateComment(validatedArgs); return { content: [ { type: 'text', text: `Comment ${result.id} updated successfully`, }, ], }; } case 'delete_comment': { const validatedArgs = await deleteCommentSchema.validate(args); const _result = await jiraClient.deleteComment(validatedArgs); return { content: [ { type: 'text', text: `Comment ${validatedArgs.commentId} deleted successfully`, }, ], }; } default: throw new Error(`Unknown comment tool: ${name}`); } } - src/schemas/index.ts:146-150 (schema)getCommentsSchema defines the input validation for 'get_comments': issueKey (required string), startAt (optional number, min 0, default 0), and maxResults (optional number, min 1, max 100, default 50). A GetCommentsInput type is inferred on line 254.
export const getCommentsSchema = yup.object({ issueKey: yup.string().required('Issue key is required'), startAt: yup.number().min(0).default(0), maxResults: yup.number().min(1).max(100).default(50), }); - src/tools/comments.ts:46-72 (registration)The tool 'get_comments' is defined as a Tool object with name, description, and inputSchema. It's returned from createCommentTools() which is called in src/index.ts (line 44) during tool listing registration.
{ name: 'get_comments', description: 'Get comments for a Jira issue with pagination support. Returns comments with pagination metadata to help navigate through large comment lists.', inputSchema: { type: 'object', properties: { issueKey: { type: 'string', description: 'The issue key to get comments for (e.g., "PROJ-123")', }, startAt: { type: 'number', description: 'Starting index for pagination (0-based). Use this to get the next page of comments. Default: 0', default: 0, minimum: 0, }, maxResults: { type: 'number', description: 'Maximum number of comments to return per page (1-100). Use smaller values for faster responses. Default: 50', default: 50, minimum: 1, maximum: 100, }, }, required: ['issueKey'], }, }, - src/jira-client.ts:359-370 (helper)The JiraClient.getComments() method calls the Jira API (issueComments.getComments) with issueKey, startAt, and maxResults, returning the raw paginated comments response.
async getComments(input: GetCommentsInput) { try { const response = await this.jira.issueComments.getComments({ issueIdOrKey: input.issueKey, startAt: input.startAt, maxResults: input.maxResults, }); return response; } catch (error) { throw new Error(`Failed to get comments: ${error instanceof Error ? error.message : 'Unknown error'}`); } } - src/index.ts:78-84 (registration)The routing logic in the MCP server's CallToolRequestSchema handler: when name starts with 'get_comments', it delegates to handleCommentTool().
} else if ( name.startsWith('create_comment') || name.startsWith('get_comments') || name.startsWith('update_comment') || name.startsWith('delete_comment') ) { return await handleCommentTool(name, args || {}, this.jiraClient);