feat: implement next-task MCP command

- Create direct function wrapper in next-task.js with error handling and caching

- Add MCP tool integration for finding the next task to work on

- Update task-master-core.js to expose nextTaskDirect function

- Update changeset to document the new command
This commit is contained in:
Eyal Toledano
2025-03-31 12:00:23 -04:00
parent 219b40b516
commit 729ae4d2d5
7 changed files with 176 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
/**
* tools/next-task.js
* Tool to find the next task to work on
*/
import { z } from "zod";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { nextTaskDirect } from "../core/task-master-core.js";
/**
* Register the next-task tool with the MCP server
* @param {Object} server - FastMCP server instance
*/
export function registerNextTaskTool(server) {
server.addTool({
name: "next_task",
description: "Find the next task to work on based on dependencies and status",
parameters: z.object({
file: z.string().optional().describe("Path to the tasks file"),
projectRoot: z
.string()
.optional()
.describe(
"Root directory of the project (default: current working directory)"
),
}),
execute: async (args, { log }) => {
try {
log.info(`Finding next task with args: ${JSON.stringify(args)}`);
// Call the direct function wrapper
const result = await nextTaskDirect(args, log);
// Log result
if (result.success) {
if (result.data.nextTask) {
log.info(`Successfully found next task ID: ${result.data.nextTask.id}${result.fromCache ? ' (from cache)' : ''}`);
} else {
log.info(`No eligible next task found${result.fromCache ? ' (from cache)' : ''}`);
}
} else {
log.error(`Failed to find next task: ${result.error.message}`);
}
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error finding next task');
} catch (error) {
log.error(`Error in next-task tool: ${error.message}`);
return createErrorResponse(`Failed to find next task: ${error.message}`);
}
},
});
}