Adds update direct function into MCP.

This commit is contained in:
Eyal Toledano
2025-03-31 00:49:16 -04:00
parent a49f5a117b
commit 450549d875
7 changed files with 341 additions and 62 deletions

View File

@@ -11,6 +11,7 @@ import { registerExpandTaskTool } from "./expandTask.js";
import { registerNextTaskTool } from "./nextTask.js";
import { registerAddTaskTool } from "./addTask.js";
import { registerParsePRDTool } from "./parsePRD.js";
import { registerUpdateTool } from "./update.js";
/**
* Register all Task Master tools with the MCP server
@@ -24,6 +25,7 @@ export function registerTaskMasterTools(server) {
registerNextTaskTool(server);
registerAddTaskTool(server);
registerParsePRDTool(server);
registerUpdateTool(server);
}
export default {

View File

@@ -1,10 +1,13 @@
/**
* tools/parsePRD.js
* Tool to parse PRD documents and generate Task Master tasks
* Tool to parse PRD document and generate tasks
*/
import { z } from "zod";
import { executeMCPToolAction } from "./utils.js";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { parsePRDDirect } from "../core/task-master-core.js";
/**
@@ -14,28 +17,34 @@ import { parsePRDDirect } from "../core/task-master-core.js";
export function registerParsePRDTool(server) {
server.addTool({
name: "parsePRD",
description: "Parse a PRD document and generate Task Master tasks",
description: "Parse PRD document and generate tasks",
parameters: z.object({
input: z
.string()
.optional()
.describe("Path to the PRD text file (default: sample-prd.txt)"),
numTasks: z
.number()
.optional()
.describe("Number of tasks to generate"),
input: z.string().describe("Path to the PRD document file"),
numTasks: z.union([z.number(), z.string()]).optional().describe("Number of tasks to generate (default: 10)"),
output: z.string().optional().describe("Output path for tasks.json file (default: tasks/tasks.json)"),
projectRoot: z
.string()
.optional()
.describe("Root directory of the project (default: current working directory)")
.describe(
"Root directory of the project (default: current working directory)"
),
}),
execute: async (args, { log }) => {
return executeMCPToolAction({
actionFn: parsePRDDirect,
args,
log,
actionName: "Parse PRD and generate tasks"
});
try {
log.info(`Parsing PRD document with args: ${JSON.stringify(args)}`);
// Call the direct function wrapper
const result = await parsePRDDirect(args, log);
// Log result
log.info(`${result.success ? `Successfully generated ${result.data?.taskCount || 0} tasks` : 'Failed to parse PRD'}`);
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error parsing PRD document');
} catch (error) {
log.error(`Error in parsePRD tool: ${error.message}`);
return createErrorResponse(error.message);
}
},
});
}

View File

@@ -0,0 +1,51 @@
/**
* tools/update.js
* Tool to update tasks based on new context/prompt
*/
import { z } from "zod";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { updateTasksDirect } from "../core/task-master-core.js";
/**
* Register the update tool with the MCP server
* @param {Object} server - FastMCP server instance
*/
export function registerUpdateTool(server) {
server.addTool({
name: "update",
description: "Update tasks with ID >= specified ID based on the provided prompt",
parameters: z.object({
from: z.union([z.number(), z.string()]).describe("Task ID from which to start updating"),
prompt: z.string().describe("Explanation of changes or new context"),
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 tasks with args: ${JSON.stringify(args)}`);
// Call the direct function wrapper
const result = await updateTasksDirect(args, log);
// Log result
log.info(`${result.success ? `Successfully updated tasks from ID ${args.from}` : 'Failed to update tasks'}`);
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error updating tasks');
} catch (error) {
log.error(`Error in update tool: ${error.message}`);
return createErrorResponse(error.message);
}
},
});
}