feat(mcp): Implement update-task MCP command for updating single tasks by ID with proper direct function wrapper, MCP tool implementation, and registration

This commit is contained in:
Eyal Toledano
2025-03-31 02:02:01 -04:00
parent 74dcf3b5f4
commit a186cb43e3
7 changed files with 164 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import { registerNextTaskTool } from "./nextTask.js";
import { registerAddTaskTool } from "./addTask.js";
import { registerParsePRDTool } from "./parsePRD.js";
import { registerUpdateTool } from "./update.js";
import { registerUpdateTaskTool } from "./update-task.js";
/**
* Register all Task Master tools with the MCP server
@@ -26,6 +27,7 @@ export function registerTaskMasterTools(server) {
registerAddTaskTool(server);
registerParsePRDTool(server);
registerUpdateTool(server);
registerUpdateTaskTool(server);
}
export default {

View File

@@ -0,0 +1,51 @@
/**
* tools/update-task.js
* Tool to update a single task by ID with new information
*/
import { z } from "zod";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { updateTaskByIdDirect } from "../core/task-master-core.js";
/**
* Register the update-task tool with the MCP server
* @param {Object} server - FastMCP server instance
*/
export function registerUpdateTaskTool(server) {
server.addTool({
name: "update-task",
description: "Updates a single task by ID with new information",
parameters: z.object({
id: z.union([z.number(), z.string()]).describe("ID of the task to update"),
prompt: z.string().describe("New information or context to update the task"),
research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
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(`Updating task with args: ${JSON.stringify(args)}`);
// Call the direct function wrapper
const result = await updateTaskByIdDirect(args, log);
// Log result
log.info(`${result.success ? `Successfully updated task with ID ${args.id}` : 'Failed to update task'}`);
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error updating task');
} catch (error) {
log.error(`Error in update-task tool: ${error.message}`);
return createErrorResponse(error.message);
}
},
});
}