task-master-marcus-ver
Version:
A task management system for ambitious AI-driven development that doesn't overwhelm and confuse Cursor.
93 lines (87 loc) • 2.92 kB
JavaScript
/**
* tools/parsePRD.js
* Tool to parse PRD document and generate tasks
*/
import { z } from 'zod';
import path from 'path';
import {
handleApiResult,
createErrorResponse,
withNormalizedProjectRoot
} from './utils.js';
import { addPRDFile } from '../core/task-master-core.js'; // replace this
/**
* Register the parse_prd tool
* @param {Object} server - FastMCP server instance
*/
export function registerAddPRDTool(server) {
server.addTool({
name: 'generate_prd',
description:
"Generate a Product Requirements Document (PRD) text file to automatically generate initial tasks. Reinitializing the project is not necessary to run this tool. It is recommended to run parse-prd after initializing the project and creating/importing a prd.txt file in the project root's scripts/ directory.",
parameters: z.object({
input: z
.string()
// .optional()
// .default('scripts/prd.txt')
.describe("User's requirements for the automation script they want. Ask about the process to automate and the apps involved in the automation."),
// numTasks: z
// .string()
// .optional()
// .describe(
// 'Approximate number of top-level tasks to generate (default: 10). As the agent, if you have enough information, ensure to enter a number of tasks that would logically scale with project complexity. Avoid entering numbers above 50 due to context window limitations.'
// ),
output: z
.string()
.optional()
.describe(
'Output path for prd.txt file (default: scripts/prd.txt)'
),
force: z
.boolean()
.optional()
.default(true)
.describe('Overwrite existing output file without prompting.'),
append: z
.boolean()
.optional()
.default(false)
.describe('Append generated tasks to existing file.'),
projectRoot: z
.string()
.describe('The directory of the project. Must be relative path.')
}),
execute: withNormalizedProjectRoot(async (args, { log, session }) => {
const toolName = 'generate_prd';
try {
log.info(
`Executing ${toolName} tool with args: ${JSON.stringify(args)}`
);
// Call Direct Function - Pass relevant args including projectRoot
const result = await addPRDFile(
{
input: args.input,
output: args.output,
// numTasks: args.numTasks,
force: args.force,
append: args.append,
projectRoot: args.projectRoot
},
log,
{ session }
);
log.info(
`${toolName}: Direct function result: success=${result.success}`
);
return handleApiResult(result, log, 'Error parsing PRD');
} catch (error) {
log.error(
`Critical error in ${toolName} tool execute: ${error.message}`
);
return createErrorResponse(
`Internal tool error (${toolName}): ${error.message}`
);
}
})
});
}