From 46329fc82bed76b4753f7862af34f7bf113343de Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 18 Apr 2026 00:29:16 +0300 Subject: [PATCH] fix(mcp): Include subtasks in get_task API response (#1040) Add Subtasks association to the findTaskByIdentifier function so that the get_task MCP API endpoint returns subtasks along with the main task. This enables clients to access the full task hierarchy in a single API call. The serializeTask function already supported subtasks serialization, so this change only required updating the query includes to load the Subtasks relation with proper ordering and Tag associations. Fixes #1029 --- backend/modules/mcp/tools/taskTools.js | 34 ++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/backend/modules/mcp/tools/taskTools.js b/backend/modules/mcp/tools/taskTools.js index 36d80fb..66de08a 100644 --- a/backend/modules/mcp/tools/taskTools.js +++ b/backend/modules/mcp/tools/taskTools.js @@ -15,23 +15,37 @@ const { Task, Project, Tag } = require('../../../models'); async function findTaskByIdentifier(identifier, userId) { const isNumeric = !isNaN(identifier); + const includeOptions = [ + { model: Project, as: 'Project' }, + { model: Tag, as: 'Tags' }, + { + model: Task, + as: 'Subtasks', + required: false, + include: [ + { + model: Tag, + as: 'Tags', + through: { attributes: [] }, + }, + ], + separate: true, + order: [ + ['order', 'ASC'], + ['created_at', 'ASC'], + ], + }, + ]; + if (isNumeric) { return await taskRepository.findByIdAndUser( parseInt(identifier), userId, - { - include: [ - { model: Project, as: 'Project' }, - { model: Tag, as: 'Tags' }, - ], - } + { include: includeOptions } ); } else { return await taskRepository.findByUid(identifier, { - include: [ - { model: Project, as: 'Project' }, - { model: Tag, as: 'Tags' }, - ], + include: includeOptions, }); } }