getTaskComments
Retrieve task comments from Teamwork by task ID, with options to filter, sort, and paginate results for efficient task management.
Instructions
Get comments for a specific task from Teamwork
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commentStatus | No | Filter by comment status | |
| orderBy | No | Order by field | |
| orderMode | No | Order mode | |
| page | No | Page number for pagination | |
| pageSize | No | Number of items per page | |
| searchTerm | No | Filter by comment content | |
| taskId | Yes | The ID of the task to retrieve comments for | |
| updatedAfter | No | Filter by updated after date (ISO 8601 format) |
Implementation Reference
- The main handler function for the 'getTaskComments' tool. It processes the input parameters, calls the underlying teamworkService.getTaskComments, formats the response as MCP content, and handles errors.export async function handleGetTaskComments(input: any) { logger.info('Calling teamworkService.getTaskComments()'); logger.info(`Task ID: ${input?.taskId}`); try { const taskId = String(input?.taskId); if (!taskId) { throw new Error("Task ID is required"); } // Extract optional parameters const options: Record<string, any> = {}; if (input.page) options.page = input.page; if (input.pageSize) options.pageSize = input.pageSize; if (input.orderBy) options.orderBy = input.orderBy; if (input.orderMode) options.orderMode = input.orderMode; if (input.searchTerm) options.searchTerm = input.searchTerm; if (input.updatedAfter) options.updatedAfter = input.updatedAfter; if (input.commentStatus) options.commentStatus = input.commentStatus; const comments = await teamworkService.getTaskComments(taskId, options); return { content: [{ type: "text", text: JSON.stringify(comments, null, 2) }] }; } catch (error: any) { logger.error(`Error in getTaskComments handler: ${error.message}`); return { content: [{ type: "text", text: `Error retrieving task comments: ${error.message}` }] }; } }
- The schema/definition for the 'getTaskComments' tool, including input schema with parameters like taskId (required), pagination, ordering, filters, and annotations.export const getTaskCommentsDefinition = { name: "getTaskComments", description: "Get comments for a specific task from Teamwork", inputSchema: { type: "object", properties: { taskId: { type: "integer", description: "The ID of the task to retrieve comments for" }, page: { type: "integer", description: "Page number for pagination" }, pageSize: { type: "integer", description: "Number of items per page" }, orderBy: { type: "string", description: "Order by field", enum: ["all", "date", "project", "user", "type"] }, orderMode: { type: "string", description: "Order mode", enum: ["asc", "desc"] }, searchTerm: { type: "string", description: "Filter by comment content" }, updatedAfter: { type: "string", description: "Filter by updated after date (ISO 8601 format)" }, commentStatus: { type: "string", description: "Filter by comment status", enum: ["all", "read", "unread"] } }, required: ["taskId"] }, annotations: { title: "Get Task Comments", readOnlyHint: false, destructiveHint: false, openWorldHint: false } };
- src/tools/index.ts:81-81 (registration)Registration of the 'getTaskComments' tool in the toolPairs array, pairing its definition and handler for use in toolDefinitions and toolHandlersMap.{ definition: getTaskComments, handler: handleGetTaskComments },
- Helper service function getTaskComments that makes the actual API call to Teamwork to fetch comments for a task, used by the tool handler.export const getTaskComments = async (taskId: string, options: any = {}) => { try { const api = ensureApiClient(); const response = await api.get(`/tasks/${taskId}/comments.json`, { params: options }); return response.data; } catch (error: any) { logger.error(`Error fetching comments for task ${taskId}: ${error.message}`); throw new Error(`Failed to fetch comments for task ${taskId}`); } };
- src/tools/index.ts:24-24 (registration)Import statement for the getTaskComments tool definition and handler in the central tools index.import { getTaskCommentsDefinition as getTaskComments, handleGetTaskComments } from './tasks/getTaskComments.js';