addSubtask
Add a subtask to a parent task to break down larger tasks into smaller, manageable components.
Instructions
Add subtask
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parentId | Yes | ||
| title | Yes |
Implementation Reference
- src/core.js:928-971 (handler)The actual implementation of addSubtask: reads tasks, creates a new subtask with an auto-incremented ID (parentId.subTaskIndex), adds it to the parent task's subtasks array, writes tasks back, and returns success with the subtaskId.
function addSubtask(workspaceRoot, parentId, options, tasksData) { const shouldWrite = options.write !== false; if (!tasksData) { tasksData = readTasks(workspaceRoot); } const { task: parentTask } = findTask(tasksData, parentId); if (!parentTask) { throw new Error(`Parent task with ID ${parentId} not found.`); } // Initialize lastSubtaskIndex if it doesn't exist if (parentTask.lastSubtaskIndex === undefined) { parentTask.lastSubtaskIndex = 0; } // Create new subtask index const subTaskIndex = parentTask.lastSubtaskIndex + 1; const newSubtaskId = `${parentId}.${subTaskIndex}`; // Create new subtask const newSubtask = { id: newSubtaskId, title: options.title, status: 'todo', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), activityLog: [] // Initialize activityLog }; // Add initial activity log entry addActivityLog(newSubtask, `Subtask created with title: "${newSubtask.title}"`); // Add to parent's subtasks parentTask.subtasks.push(newSubtask); parentTask.lastSubtaskIndex = subTaskIndex; if (shouldWrite) { writeTasks(workspaceRoot, tasksData); } // Return data instead of logging return { success: true, message: `Added new subtask (ID: ${newSubtaskId}) to task ${parentId}: "${newSubtask.title}"`, subtaskId: newSubtaskId }; } - src/mcp/server.js:69-69 (schema)MCP tool registration with inputSchema: the addSubtask tool requires parentId (number) and title (string).
{ name:'addSubtask', description:'Add subtask', inputSchema:{ type:'object', properties:{ parentId:{type:'number'}, title:{type:'string'} }, required:['parentId','title'] } }, - src/mcp/server.js:69-69 (registration)MCP tools/list registration declares the addSubtask tool with its name, description, and inputSchema.
{ name:'addSubtask', description:'Add subtask', inputSchema:{ type:'object', properties:{ parentId:{type:'number'}, title:{type:'string'} }, required:['parentId','title'] } }, - src/mcp/server.js:164-167 (registration)MCP tools/call handler: validates required parameters (parentId, title) then delegates to core.addSubtask().
case 'addSubtask': if (!args.parentId || !args.title) { sendError(id,-32602,'Missing required parameters for addSubtask: parentId and/or title'); return; } data = core.addSubtask(workspaceRoot, args.parentId, { title: args.title }); break; - src/core-fixes.js:81-96 (helper)Enhancement wrapper (enhanceAddSubtask) that ensures the returned result always has id = subtaskId for backward compatibility.
function enhanceAddSubtask(originalAddSubtask) { return function(workspaceRoot, parentId, options, tasksData) { const result = originalAddSubtask(workspaceRoot, parentId, options, tasksData); // Ensure backward compatibility if (result && result.success && result.subtaskId) { result.id = result.subtaskId; // Allow numeric-style access result.valueOf = function() { return result.subtaskId; }; result.toString = function() { return result.subtaskId; }; } return result; }; }