An AI-powered task-management system you can drop into Cursor, Lovable, Windsurf, Roo, and others.
JavaScript aicursorcursor-aicursorailovablelovable-devroocodetask-managertaskstasks-listwindsurfwindsurf-ai
fix(mcp, expand): pass projectRoot through expand/expand-all flows
Eyal Toledanof5585e6c31b0
diff --git a/.taskmasterconfig b/.taskmasterconfigindex 9b86628e..ccb7704c 100644--- a/.taskmasterconfig+++ b/.taskmasterconfig@@ -1,8 +1,8 @@{"models": {"main": {- "provider": "openai",- "modelId": "gpt-4o",+ "provider": "anthropic",+ "modelId": "claude-3-7-sonnet-20250219","maxTokens": 100000,"temperature": 0.2},diff --git a/mcp-server/src/core/direct-functions/expand-all-tasks.js b/mcp-server/src/core/direct-functions/expand-all-tasks.jsindex a7066385..9d9388bc 100644--- a/mcp-server/src/core/direct-functions/expand-all-tasks.js+++ b/mcp-server/src/core/direct-functions/expand-all-tasks.js@@ -17,14 +17,15 @@ import { createLogWrapper } from '../../tools/utils.js';* @param {boolean} [args.research] - Enable research-backed subtask generation* @param {string} [args.prompt] - Additional context to guide subtask generation* @param {boolean} [args.force] - Force regeneration of subtasks for tasks that already have them+ * @param {string} [args.projectRoot] - Project root path.* @param {Object} log - Logger object from FastMCP* @param {Object} context - Context object containing session* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}*/export async function expandAllTasksDirect(args, log, context = {}) {const { session } = context; // Extract session- // Destructure expected args- const { tasksJsonPath, num, research, prompt, force } = args;+ // Destructure expected args, including projectRoot+ const { tasksJsonPath, num, research, prompt, force, projectRoot } = args;// Create logger wrapper using the utilityconst mcpLog = createLogWrapper(log);@@ -43,7 +44,7 @@ export async function expandAllTasksDirect(args, log, context = {}) {enableSilentMode(); // Enable silent mode for the core function calltry {log.info(- `Calling core expandAllTasks with args: ${JSON.stringify({ num, research, prompt, force })}`+ `Calling core expandAllTasks with args: ${JSON.stringify({ num, research, prompt, force, projectRoot })}`);// Parse parameters (ensure correct types)@@ -52,14 +53,14 @@ export async function expandAllTasksDirect(args, log, context = {}) {const additionalContext = prompt || '';const forceFlag = force === true;- // Call the core function, passing options and the context object { session, mcpLog }+ // Call the core function, passing options and the context object { session, mcpLog, projectRoot }const result = await expandAllTasks(tasksJsonPath,numSubtasks,useResearch,additionalContext,forceFlag,- { session, mcpLog }+ { session, mcpLog, projectRoot });// Core function now returns a summary objectdiff --git a/mcp-server/src/core/direct-functions/expand-task.js b/mcp-server/src/core/direct-functions/expand-task.jsindex 43bf8f8e..0cafca43 100644--- a/mcp-server/src/core/direct-functions/expand-task.js+++ b/mcp-server/src/core/direct-functions/expand-task.js@@ -25,6 +25,7 @@ import { createLogWrapper } from '../../tools/utils.js';* @param {boolean} [args.research] - Enable research role for subtask generation.* @param {string} [args.prompt] - Additional context to guide subtask generation.* @param {boolean} [args.force] - Force expansion even if subtasks exist.+ * @param {string} [args.projectRoot] - Project root directory.* @param {Object} log - Logger object* @param {Object} context - Context object containing session* @param {Object} [context.session] - MCP Session object@@ -32,8 +33,8 @@ import { createLogWrapper } from '../../tools/utils.js';*/export async function expandTaskDirect(args, log, context = {}) {const { session } = context; // Extract session- // Destructure expected args- const { tasksJsonPath, id, num, research, prompt, force } = args;+ // Destructure expected args, including projectRoot+ const { tasksJsonPath, id, num, research, prompt, force, projectRoot } = args;// Log session root data for debugginglog.info(@@ -184,20 +185,22 @@ export async function expandTaskDirect(args, log, context = {}) {// Create logger wrapper using the utilityconst mcpLog = createLogWrapper(log);+ let wasSilent; // Declare wasSilent outside the try block// Process the requesttry {// Enable silent mode to prevent console logs from interfering with JSON response- const wasSilent = isSilentMode();+ wasSilent = isSilentMode(); // Assign inside the try blockif (!wasSilent) enableSilentMode();- // Call the core expandTask function with the wrapped logger- const result = await expandTask(+ // Call the core expandTask function with the wrapped logger and projectRoot+ const updatedTaskResult = await expandTask(tasksPath,taskId,numSubtasks,useResearch,additionalContext,- { mcpLog, session }+ { mcpLog, session, projectRoot },+ forceFlag);// Restore normal loggingdiff --git a/mcp-server/src/tools/expand-task.js b/mcp-server/src/tools/expand-task.jsindex 0655a2a6..684ab9fa 100644--- a/mcp-server/src/tools/expand-task.js+++ b/mcp-server/src/tools/expand-task.js@@ -4,13 +4,10 @@*/import { z } from 'zod';-import {- handleApiResult,- createErrorResponse,- getProjectRootFromSession-} from './utils.js';+import { handleApiResult, createErrorResponse } from './utils.js';import { expandTaskDirect } from '../core/task-master-core.js';import { findTasksJsonPath } from '../core/utils/path-utils.js';+import path from 'path';/*** Register the expand-task tool with the MCP server@@ -51,19 +48,16 @@ export function registerExpandTaskTool(server) {try {log.info(`Starting expand-task with args: ${JSON.stringify(args)}`);- // Get project root from args or session- const rootFolder =- args.projectRoot || getProjectRootFromSession(session, log);-- // Ensure project root was determined- if (!rootFolder) {+ const rootFolder = args.projectRoot;+ if (!rootFolder || !path.isAbsolute(rootFolder)) {+ log.error(+ `expand-task: projectRoot is required and must be absolute.`+ );return createErrorResponse(- 'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'+ 'projectRoot is required and must be absolute.');}- log.info(`Project root resolved to: ${rootFolder}`);-// Resolve the path to tasks.json using the utilitylet tasksJsonPath;try {@@ -71,35 +65,39 @@ export function registerExpandTaskTool(server) {{ projectRoot: rootFolder, file: args.file },log);+ log.info(`expand-task: Resolved tasks path: ${tasksJsonPath}`);} catch (error) {- log.error(`Error finding tasks.json: ${error.message}`);+ log.error(`expand-task: Error finding tasks.json: ${error.message}`);return createErrorResponse(- `Failed to find tasks.json: ${error.message}`+ `Failed to find tasks.json within project root '${rootFolder}': ${error.message}`);}- // Call direct function with only session in the context, not reportProgress- // Use the pattern recommended in the MCP guidelinesconst result = await expandTaskDirect({- // Pass the explicitly resolved pathtasksJsonPath: tasksJsonPath,- // Pass other relevant argsid: args.id,num: args.num,research: args.research,prompt: args.prompt,- force: args.force // Need to add force to parameters+ force: args.force,+ projectRoot: rootFolder},log,{ session }- ); // Only pass session, NOT reportProgress+ );- // Return the result+ log.info(+ `expand-task: Direct function result: success=${result.success}`+ );return handleApiResult(result, log, 'Error expanding task');} catch (error) {- log.error(`Error in expand task tool: ${error.message}`);- return createErrorResponse(error.message);+ log.error(+ `Critical error in ${toolName} tool execute: ${error.message}`+ );+ return createErrorResponse(+ `Internal tool error (${toolName}): ${error.message}`+ );}}});diff --git a/scripts/modules/task-manager/expand-task.js b/scripts/modules/task-manager/expand-task.jsindex 15bf9fb6..df61c394 100644--- a/scripts/modules/task-manager/expand-task.js+++ b/scripts/modules/task-manager/expand-task.js@@ -503,7 +503,8 @@ async function expandTask(prompt: promptContent,systemPrompt: systemPrompt, // Use the determined system promptrole,- session+ session,+ projectRoot});logger.info('Successfully received text response from AI service',