From 86d8f00af809887ee0ba0ba7157cc555e0d07c38 Mon Sep 17 00:00:00 2001 From: Shrey Paharia Date: Thu, 22 May 2025 14:39:36 +0530 Subject: [PATCH] Add next task to set status for mcp server (#558) --- .changeset/twenty-plums-act.md | 6 +++ .../core/direct-functions/set-task-status.js | 37 ++++++++++++++++++- mcp-server/src/tools/set-task-status.js | 30 +++++++++++++-- 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 .changeset/twenty-plums-act.md diff --git a/.changeset/twenty-plums-act.md b/.changeset/twenty-plums-act.md new file mode 100644 index 00000000..2a62f5de --- /dev/null +++ b/.changeset/twenty-plums-act.md @@ -0,0 +1,6 @@ +--- +'task-master-ai': minor +--- + +Add next task to set task status response +Status: DONE \ No newline at end of file diff --git a/mcp-server/src/core/direct-functions/set-task-status.js b/mcp-server/src/core/direct-functions/set-task-status.js index 39845ad1..9711b771 100644 --- a/mcp-server/src/core/direct-functions/set-task-status.js +++ b/mcp-server/src/core/direct-functions/set-task-status.js @@ -9,7 +9,7 @@ import { disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js'; - +import { nextTaskDirect } from './next-task.js'; /** * Direct function wrapper for setTaskStatus with error handling. * @@ -19,7 +19,7 @@ import { */ export async function setTaskStatusDirect(args, log) { // Destructure expected args, including the resolved tasksJsonPath - const { tasksJsonPath, id, status } = args; + const { tasksJsonPath, id, status, complexityReportPath } = args; try { log.info(`Setting task status with args: ${JSON.stringify(args)}`); @@ -85,6 +85,39 @@ export async function setTaskStatusDirect(args, log) { }, fromCache: false // This operation always modifies state and should never be cached }; + + // If the task was completed, attempt to fetch the next task + if (result.data.status === 'done') { + try { + log.info(`Attempting to fetch next task for task ${taskId}`); + const nextResult = await nextTaskDirect( + { + tasksJsonPath: tasksJsonPath, + reportPath: complexityReportPath + }, + log + ); + + if (nextResult.success) { + log.info( + `Successfully retrieved next task: ${nextResult.data.nextTask}` + ); + result.data = { + ...result.data, + nextTask: nextResult.data.nextTask, + isNextSubtask: nextResult.data.isSubtask, + nextSteps: nextResult.data.nextSteps + }; + } else { + log.warn( + `Failed to retrieve next task: ${nextResult.error?.message || 'Unknown error'}` + ); + } + } catch (nextErr) { + log.error(`Error retrieving next task: ${nextErr.message}`); + } + } + return result; } catch (error) { log.error(`Error setting task status: ${error.message}`); diff --git a/mcp-server/src/tools/set-task-status.js b/mcp-server/src/tools/set-task-status.js index 04ae9052..8a28658d 100644 --- a/mcp-server/src/tools/set-task-status.js +++ b/mcp-server/src/tools/set-task-status.js @@ -9,8 +9,14 @@ import { createErrorResponse, withNormalizedProjectRoot } from './utils.js'; -import { setTaskStatusDirect } from '../core/task-master-core.js'; -import { findTasksJsonPath } from '../core/utils/path-utils.js'; +import { + setTaskStatusDirect, + nextTaskDirect +} from '../core/task-master-core.js'; +import { + findTasksJsonPath, + findComplexityReportPath +} from '../core/utils/path-utils.js'; import { TASK_STATUS_OPTIONS } from '../../../src/constants/task-status.js'; /** @@ -33,6 +39,12 @@ export function registerSetTaskStatusTool(server) { "New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'." ), file: z.string().optional().describe('Absolute path to the tasks file'), + complexityReport: z + .string() + .optional() + .describe( + 'Path to the complexity report file (relative to project root or absolute)' + ), projectRoot: z .string() .describe('The directory of the project. Must be an absolute path.') @@ -55,11 +67,23 @@ export function registerSetTaskStatusTool(server) { ); } + let complexityReportPath; + try { + complexityReportPath = findComplexityReportPath( + args.projectRoot, + args.complexityReport, + log + ); + } catch (error) { + log.error(`Error finding complexity report: ${error.message}`); + } + const result = await setTaskStatusDirect( { tasksJsonPath: tasksJsonPath, id: args.id, - status: args.status + status: args.status, + complexityReportPath }, log );