feat(mcp): Fix parse-prd tool path resolution
Refactors parse-prd MCP tool to properly handle project root and path resolution, fixing the 'Input file not found: /scripts/prd.txt' error. Key changes include: Made projectRoot a required parameter, prioritized args.projectRoot over session-derived paths, added validation to prevent parsing in invalid directories (/, home dir), improved error handling with detailed messages, and added creation of output directory if needed. This resolves issues similar to those fixed in initialize-project, where the tool was incorrectly resolving paths when session context was incomplete.
This commit is contained in:
@@ -19,7 +19,7 @@ export function registerParsePRDTool(server) {
|
||||
server.addTool({
|
||||
name: 'parse_prd',
|
||||
description:
|
||||
'Parse a Product Requirements Document (PRD) text file to automatically generate initial tasks.',
|
||||
"Parse 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()
|
||||
@@ -43,22 +43,35 @@ export function registerParsePRDTool(server) {
|
||||
.describe('Allow overwriting an existing tasks.json file.'),
|
||||
projectRoot: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'Absolute path to the root directory of the project (default: automatically detected from session or CWD)'
|
||||
'Absolute path to the root directory of the project. Required - ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY.'
|
||||
)
|
||||
}),
|
||||
execute: async (args, { log, session }) => {
|
||||
try {
|
||||
log.info(`Parsing PRD with args: ${JSON.stringify(args)}`);
|
||||
|
||||
let rootFolder = getProjectRootFromSession(session, log);
|
||||
// Make sure projectRoot is passed directly in args or derive from session
|
||||
// We prioritize projectRoot from args over session-derived path
|
||||
let rootFolder = args.projectRoot;
|
||||
|
||||
if (!rootFolder && args.projectRoot) {
|
||||
rootFolder = args.projectRoot;
|
||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||
// Only if args.projectRoot is undefined or null, try to get it from session
|
||||
if (!rootFolder) {
|
||||
log.warn(
|
||||
'projectRoot not provided in args, attempting to derive from session'
|
||||
);
|
||||
rootFolder = getProjectRootFromSession(session, log);
|
||||
|
||||
if (!rootFolder) {
|
||||
const errorMessage =
|
||||
'Could not determine project root directory. Please provide projectRoot parameter.';
|
||||
log.error(errorMessage);
|
||||
return createErrorResponse(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
log.info(`Using project root: ${rootFolder} for PRD parsing`);
|
||||
|
||||
const result = await parsePRDDirect(
|
||||
{
|
||||
projectRoot: rootFolder,
|
||||
|
||||
Reference in New Issue
Block a user