Implement expand-all MCP command for expanding all pending tasks with subtasks

This commit is contained in:
Eyal Toledano
2025-03-31 13:10:10 -04:00
parent 995e95263c
commit 00e01d1d93
7 changed files with 131 additions and 4 deletions

View File

@@ -15,4 +15,5 @@
- Implement remove-subtask MCP command for removing subtasks from parent tasks
- Implement analyze-complexity MCP command for analyzing task complexity and generating recommendations
- Implement clear-subtasks MCP command for clearing subtasks from parent tasks
- Implement expand-all MCP command for expanding all pending tasks with subtasks
- Document MCP server naming conventions in architecture.mdc and mcp.mdc files (file names use kebab-case, direct functions use camelCase with Direct suffix, tool registration functions use camelCase with Tool suffix, and MCP tool names use snake_case)

View File

@@ -0,0 +1,70 @@
/**
* Direct function wrapper for expandAllTasks
*/
import { expandAllTasks } from '../../../../scripts/modules/task-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
/**
* Expand all pending tasks with subtasks
* @param {Object} args - Function arguments
* @param {number|string} [args.num] - Number of subtasks to generate
* @param {boolean} [args.research] - Enable Perplexity AI for 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.file] - Path to the tasks file
* @param {string} [args.projectRoot] - Project root directory
* @param {Object} log - Logger object
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
*/
export async function expandAllTasksDirect(args, log) {
try {
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
// Parse parameters
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
const useResearch = args.research === true;
const additionalContext = args.prompt || '';
const forceFlag = args.force === true;
log.info(`Expanding all tasks with ${numSubtasks || 'default'} subtasks each...`);
if (useResearch) {
log.info('Using Perplexity AI for research-backed subtask generation');
}
if (additionalContext) {
log.info(`Additional context: "${additionalContext}"`);
}
if (forceFlag) {
log.info('Force regeneration of subtasks is enabled');
}
// Call the core function
await expandAllTasks(numSubtasks, useResearch, additionalContext, forceFlag);
// The expandAllTasks function doesn't have a return value, so we'll create our own success response
return {
success: true,
data: {
message: "Successfully expanded all pending tasks with subtasks",
details: {
numSubtasks: numSubtasks,
research: useResearch,
prompt: additionalContext,
force: forceFlag
}
}
};
} catch (error) {
log.error(`Error in expandAllTasksDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -21,6 +21,7 @@ import { addSubtaskDirect } from './direct-functions/add-subtask.js';
import { removeSubtaskDirect } from './direct-functions/remove-subtask.js';
import { analyzeTaskComplexityDirect } from './direct-functions/analyze-task-complexity.js';
import { clearSubtasksDirect } from './direct-functions/clear-subtasks.js';
import { expandAllTasksDirect } from './direct-functions/expand-all-tasks.js';
// Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js';
@@ -42,7 +43,8 @@ export const directFunctions = new Map([
['addSubtaskDirect', addSubtaskDirect],
['removeSubtaskDirect', removeSubtaskDirect],
['analyzeTaskComplexityDirect', analyzeTaskComplexityDirect],
['clearSubtasksDirect', clearSubtasksDirect]
['clearSubtasksDirect', clearSubtasksDirect],
['expandAllTasksDirect', expandAllTasksDirect]
]);
// Re-export all direct function implementations
@@ -62,5 +64,6 @@ export {
addSubtaskDirect,
removeSubtaskDirect,
analyzeTaskComplexityDirect,
clearSubtasksDirect
clearSubtasksDirect,
expandAllTasksDirect
};

View File

@@ -0,0 +1,51 @@
/**
* tools/expand-all.js
* Tool for expanding all pending tasks with subtasks
*/
import { z } from "zod";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { expandAllTasksDirect } from "../core/task-master-core.js";
/**
* Register the expandAll tool with the MCP server
* @param {Object} server - FastMCP server instance
*/
export function registerExpandAllTool(server) {
server.addTool({
name: "expand_all",
description: "Expand all pending tasks into subtasks",
parameters: z.object({
num: z.union([z.number(), z.string()]).optional().describe("Number of subtasks to generate for each task"),
research: z.boolean().optional().describe("Enable Perplexity AI for research-backed subtask generation"),
prompt: z.string().optional().describe("Additional context to guide subtask generation"),
force: z.boolean().optional().describe("Force regeneration of subtasks for tasks that already have them"),
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
}),
execute: async (args, { log }) => {
try {
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
// Call the direct function wrapper
const result = await expandAllTasksDirect(args, log);
// Log result
if (result.success) {
log.info(`All tasks expanded successfully: ${result.data.message}`);
} else {
log.error(`Failed to expand tasks: ${result.error.message}`);
}
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error expanding tasks');
} catch (error) {
log.error(`Error in expandAll tool: ${error.message}`);
return createErrorResponse(error.message);
}
},
});
}

View File

@@ -19,6 +19,7 @@ import { registerAddSubtaskTool } from "./add-subtask.js";
import { registerRemoveSubtaskTool } from "./remove-subtask.js";
import { registerAnalyzeTool } from "./analyze.js";
import { registerClearSubtasksTool } from "./clear-subtasks.js";
import { registerExpandAllTool } from "./expand-all.js";
/**
* Register all Task Master tools with the MCP server
@@ -40,6 +41,7 @@ export function registerTaskMasterTools(server) {
registerRemoveSubtaskTool(server);
registerAnalyzeTool(server);
registerClearSubtasksTool(server);
registerExpandAllTool(server);
logger.info("Registered all Task Master tools with MCP server");
}

View File

@@ -769,7 +769,7 @@ Following MCP implementation standards:
- Unit test for clearSubtasksDirect.js
- Integration test for MCP tool
## 30. Implement expand-all MCP command [pending]
## 30. Implement expand-all MCP command [done]
### Dependencies: None
### Description: Create direct function wrapper and MCP tool for expanding all tasks into subtasks.
### Details:

View File

@@ -1618,7 +1618,7 @@
"title": "Implement expand-all MCP command",
"description": "Create direct function wrapper and MCP tool for expanding all tasks into subtasks.",
"details": "Following MCP implementation standards:\n\n1. Create expandAllTasksDirect.js in mcp-server/src/core/direct-functions/:\n - Import expandAllTasks from task-manager.js\n - Handle file paths using findTasksJsonPath utility\n - Process arguments: prompt, num, force, research\n - Validate inputs and handle errors with try/catch\n - Return standardized { success, data/error } object\n\n2. Export from task-master-core.js:\n - Import the function from its file\n - Add to directFunctions map\n\n3. Create expand-all.js MCP tool in mcp-server/src/tools/:\n - Import z from zod for parameter schema\n - Import executeMCPToolAction from ./utils.js\n - Import expandAllTasksDirect from task-master-core.js\n - Define parameters matching CLI options using zod schema\n - Implement registerExpandAllTool(server) with server.addTool\n - Use executeMCPToolAction in execute method\n\n4. Register in tools/index.js with tool name 'expand_all'\n\n5. Add to .cursor/mcp.json with appropriate schema\n\n6. Write tests following testing guidelines:\n - Unit test for expandAllTasksDirect.js\n - Integration test for MCP tool",
"status": "pending",
"status": "done",
"dependencies": [],
"parentTaskId": 23
},