Implement remove-dependency MCP command for removing dependencies from tasks

This commit is contained in:
Eyal Toledano
2025-03-31 13:51:39 -04:00
parent 7f0cdf9046
commit fba6131db7
7 changed files with 132 additions and 4 deletions

View File

@@ -16,5 +16,6 @@
- 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
- Implement remove-dependency MCP command for removing dependencies from tasks
- 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)
- Enhance task show view with a color-coded progress bar for visualizing subtask completion percentage

View File

@@ -0,0 +1,73 @@
/**
* Direct function wrapper for removeDependency
*/
import { removeDependency } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
/**
* Remove a dependency from a task
* @param {Object} args - Function arguments
* @param {string|number} args.id - Task ID to remove dependency from
* @param {string|number} args.dependsOn - Task ID to remove as a dependency
* @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 removeDependencyDirect(args, log) {
try {
log.info(`Removing dependency with args: ${JSON.stringify(args)}`);
// Validate required parameters
if (!args.id) {
return {
success: false,
error: {
code: 'INPUT_VALIDATION_ERROR',
message: 'Task ID (id) is required'
}
};
}
if (!args.dependsOn) {
return {
success: false,
error: {
code: 'INPUT_VALIDATION_ERROR',
message: 'Dependency ID (dependsOn) is required'
}
};
}
// Find the tasks.json path
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
// Format IDs for the core function
const taskId = args.id.includes && args.id.includes('.') ? args.id : parseInt(args.id, 10);
const dependencyId = args.dependsOn.includes && args.dependsOn.includes('.') ? args.dependsOn : parseInt(args.dependsOn, 10);
log.info(`Removing dependency: task ${taskId} no longer depends on ${dependencyId}`);
// Call the core function
await removeDependency(tasksPath, taskId, dependencyId);
return {
success: true,
data: {
message: `Successfully removed dependency: Task ${taskId} no longer depends on ${dependencyId}`,
taskId: taskId,
dependencyId: dependencyId
}
};
} catch (error) {
log.error(`Error in removeDependencyDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -22,6 +22,7 @@ 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';
import { removeDependencyDirect } from './direct-functions/remove-dependency.js';
// Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js';
@@ -44,7 +45,8 @@ export const directFunctions = new Map([
['removeSubtaskDirect', removeSubtaskDirect],
['analyzeTaskComplexityDirect', analyzeTaskComplexityDirect],
['clearSubtasksDirect', clearSubtasksDirect],
['expandAllTasksDirect', expandAllTasksDirect]
['expandAllTasksDirect', expandAllTasksDirect],
['removeDependencyDirect', removeDependencyDirect]
]);
// Re-export all direct function implementations
@@ -65,5 +67,6 @@ export {
removeSubtaskDirect,
analyzeTaskComplexityDirect,
clearSubtasksDirect,
expandAllTasksDirect
expandAllTasksDirect,
removeDependencyDirect
};

View File

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

View File

@@ -0,0 +1,49 @@
/**
* tools/remove-dependency.js
* Tool for removing a dependency from a task
*/
import { z } from "zod";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { removeDependencyDirect } from "../core/task-master-core.js";
/**
* Register the removeDependency tool with the MCP server
* @param {Object} server - FastMCP server instance
*/
export function registerRemoveDependencyTool(server) {
server.addTool({
name: "remove_dependency",
description: "Remove a dependency from a task",
parameters: z.object({
id: z.string().describe("Task ID to remove dependency from"),
dependsOn: z.string().describe("Task ID to remove as a dependency"),
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(`Removing dependency for task ${args.id} from ${args.dependsOn} with args: ${JSON.stringify(args)}`);
// Call the direct function wrapper
const result = await removeDependencyDirect(args, log);
// Log result
if (result.success) {
log.info(`Successfully removed dependency: ${result.data.message}`);
} else {
log.error(`Failed to remove dependency: ${result.error.message}`);
}
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error removing dependency');
} catch (error) {
log.error(`Error in removeDependency tool: ${error.message}`);
return createErrorResponse(error.message);
}
},
});
}

View File

@@ -878,7 +878,7 @@ Analyze and refactor the project root handling mechanism to ensure consistent fi
### Details:
## 40. Implement remove-dependency MCP command [pending]
## 40. Implement remove-dependency MCP command [done]
### Dependencies: 23.31
### Description: Create MCP tool implementation for the remove-dependency command
### Details:

View File

@@ -1712,7 +1712,7 @@
"title": "Implement remove-dependency MCP command",
"description": "Create MCP tool implementation for the remove-dependency command",
"details": "",
"status": "pending",
"status": "done",
"dependencies": [
"23.31"
],