From 33d2569ace270e9d37d1739710d7dc4ffc3a3ae4 Mon Sep 17 00:00:00 2001 From: Shrey Paharia Date: Wed, 23 Apr 2025 23:39:03 +0530 Subject: [PATCH] fix: fixed handling for complexity report path in mcp --- mcp-server/src/core/utils/path-utils.js | 43 +++++++++++++++++++++++++ mcp-server/src/tools/get-tasks.js | 28 ++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/mcp-server/src/core/utils/path-utils.js b/mcp-server/src/core/utils/path-utils.js index 3d362a6d..bc4ef938 100644 --- a/mcp-server/src/core/utils/path-utils.js +++ b/mcp-server/src/core/utils/path-utils.js @@ -339,6 +339,49 @@ export function findPRDDocumentPath(projectRoot, explicitPath, log) { return null; } +export function findComplexityReportPath(projectRoot, explicitPath, log) { + // If explicit path is provided, check if it exists + if (explicitPath) { + const fullPath = path.isAbsolute(explicitPath) + ? explicitPath + : path.resolve(projectRoot, explicitPath); + + if (fs.existsSync(fullPath)) { + log.info(`Using provided PRD document path: ${fullPath}`); + return fullPath; + } else { + log.warn( + `Provided PRD document path not found: ${fullPath}, will search for alternatives` + ); + } + } + + // Common locations and file patterns for PRD documents + const commonLocations = [ + '', // Project root + 'scripts/' + ]; + + const commonFileNames = [ + 'complexity-report.json', + 'task-complexity-report.json' + ]; + + // Check all possible combinations + for (const location of commonLocations) { + for (const fileName of commonFileNames) { + const potentialPath = path.join(projectRoot, location, fileName); + if (fs.existsSync(potentialPath)) { + log.info(`Found PRD document at: ${potentialPath}`); + return potentialPath; + } + } + } + + log.warn(`No PRD document found in common locations within ${projectRoot}`); + return null; +} + /** * Resolves the tasks output directory path * @param {string} projectRoot - The project root directory diff --git a/mcp-server/src/tools/get-tasks.js b/mcp-server/src/tools/get-tasks.js index e6c6dec9..9b63a211 100644 --- a/mcp-server/src/tools/get-tasks.js +++ b/mcp-server/src/tools/get-tasks.js @@ -10,7 +10,10 @@ import { getProjectRootFromSession } from './utils.js'; import { listTasksDirect } from '../core/task-master-core.js'; -import { findTasksJsonPath } from '../core/utils/path-utils.js'; +import { + findTasksJsonPath, + findComplexityReportPath +} from '../core/utils/path-utils.js'; /** * Register the getTasks tool with the MCP server @@ -38,6 +41,12 @@ export function registerListTasksTool(server) { .describe( 'Path to the tasks file (relative to project root or absolute)' ), + complexityReport: z + .string() + .optional() + .describe( + 'Path to the complexity report file (relative to project root or absolute)' + ), projectRoot: z .string() .describe('The directory of the project. Must be an absolute path.') @@ -72,11 +81,26 @@ export function registerListTasksTool(server) { ); } + // Resolve the path to complexity report + let complexityReportPath; + try { + complexityReportPath = findComplexityReportPath( + rootFolder, + args.complexityReport, + log + ); + } catch (error) { + log.error(`Error finding complexity report: ${error.message}`); + return createErrorResponse( + `Failed to find complexity report: ${error.message}` + ); + } const result = await listTasksDirect( { tasksJsonPath: tasksJsonPath, status: args.status, - withSubtasks: args.withSubtasks + withSubtasks: args.withSubtasks, + reportPath: complexityReportPath }, log );