- Refactor for more reliable project root detection, particularly when running within integrated environments like Cursor IDE. Includes deriving root from script path and avoiding fallback to '/'.
- Enhance error handling in :
- Add detailed debug information (paths searched, CWD, etc.) to the error message when is not found in the provided project root.
- Improve clarity of error messages and potential solutions.
- Add verbose logging in to trace session object content and the finally resolved project root path, aiding in debugging path-related issues.
- Add default values for and to the example environment configuration.
70 lines
2.3 KiB
JavaScript
70 lines
2.3 KiB
JavaScript
/**
|
|
* tools/setTaskStatus.js
|
|
* Tool to set the status of a task
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
import {
|
|
handleApiResult,
|
|
createErrorResponse,
|
|
getProjectRootFromSession
|
|
} from "./utils.js";
|
|
import { setTaskStatusDirect } from "../core/task-master-core.js";
|
|
|
|
/**
|
|
* Register the setTaskStatus tool with the MCP server
|
|
* @param {Object} server - FastMCP server instance
|
|
*/
|
|
export function registerSetTaskStatusTool(server) {
|
|
server.addTool({
|
|
name: "set_task_status",
|
|
description: "Set the status of one or more tasks or subtasks.",
|
|
parameters: z.object({
|
|
id: z
|
|
.string()
|
|
.describe("Task ID or subtask ID (e.g., '15', '15.2'). Can be comma-separated for multiple updates."),
|
|
status: z
|
|
.string()
|
|
.describe("New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'."),
|
|
file: z.string().optional().describe("Path to the tasks file"),
|
|
projectRoot: z
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
"Root directory of the project (default: automatically detected)"
|
|
),
|
|
}),
|
|
execute: async (args, { log, session, reportProgress }) => {
|
|
try {
|
|
log.info(`Setting status of task(s) ${args.id} to: ${args.status}`);
|
|
await reportProgress({ progress: 0 });
|
|
|
|
let rootFolder = getProjectRootFromSession(session, log);
|
|
|
|
if (!rootFolder && args.projectRoot) {
|
|
rootFolder = args.projectRoot;
|
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
|
}
|
|
|
|
const result = await setTaskStatusDirect({
|
|
projectRoot: rootFolder,
|
|
...args
|
|
}, log, { reportProgress, mcpLog: log, session});
|
|
|
|
await reportProgress({ progress: 100 });
|
|
|
|
if (result.success) {
|
|
log.info(`Successfully updated status for task(s) ${args.id} to "${args.status}": ${result.data.message}`);
|
|
} else {
|
|
log.error(`Failed to update task status: ${result.error?.message || 'Unknown error'}`);
|
|
}
|
|
|
|
return handleApiResult(result, log, 'Error setting task status');
|
|
} catch (error) {
|
|
log.error(`Error in setTaskStatus tool: ${error.message}`);
|
|
return createErrorResponse(`Error setting task status: ${error.message}`);
|
|
}
|
|
},
|
|
});
|
|
}
|