feat(mcp): Implement add-dependency MCP command for creating dependency relationships between tasks

This commit is contained in:
Eyal Toledano
2025-03-31 14:24:45 -04:00
parent 9f430ca48b
commit 6a6d06766b
5 changed files with 127 additions and 2 deletions

View File

@@ -20,5 +20,6 @@
- Implement validate-dependencies MCP command for checking validity of task dependencies
- Implement fix-dependencies MCP command for automatically fixing invalid dependencies
- Implement complexity-report MCP command for displaying task complexity analysis reports
- Implement add-dependency MCP command for creating dependency relationships between 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,75 @@
/**
* add-dependency.js
* Direct function implementation for adding a dependency to a task
*/
import { addDependency } from '../../../../scripts/modules/dependency-manager.js';
import { findTasksJsonPath } from '../utils/path-utils.js';
/**
* Direct function wrapper for addDependency with error handling.
*
* @param {Object} args - Command arguments
* @param {string|number} args.id - Task ID to add dependency to
* @param {string|number} args.dependsOn - Task ID that will become 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<Object>} - Result object with success status and data/error information
*/
export async function addDependencyDirect(args, log) {
try {
log.info(`Adding 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, log);
// 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(`Adding dependency: task ${taskId} will depend on ${dependencyId}`);
// Call the core function
await addDependency(tasksPath, taskId, dependencyId);
return {
success: true,
data: {
message: `Successfully added dependency: Task ${taskId} now depends on ${dependencyId}`,
taskId: taskId,
dependencyId: dependencyId
}
};
} catch (error) {
log.error(`Error in addDependencyDirect: ${error.message}`);
return {
success: false,
error: {
code: 'CORE_FUNCTION_ERROR',
message: error.message
}
};
}
}

View File

@@ -0,0 +1,49 @@
/**
* tools/add-dependency.js
* Tool for adding a dependency to a task
*/
import { z } from "zod";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { addDependencyDirect } from "../core/task-master-core.js";
/**
* Register the addDependency tool with the MCP server
* @param {Object} server - FastMCP server instance
*/
export function registerAddDependencyTool(server) {
server.addTool({
name: "add_dependency",
description: "Add a dependency relationship between two tasks",
parameters: z.object({
id: z.string().describe("ID of task that will depend on another task"),
dependsOn: z.string().describe("ID of task that will become 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(`Adding dependency for task ${args.id} to depend on ${args.dependsOn} with args: ${JSON.stringify(args)}`);
// Call the direct function wrapper
const result = await addDependencyDirect(args, log);
// Log result
if (result.success) {
log.info(`Successfully added dependency: ${result.data.message}`);
} else {
log.error(`Failed to add dependency: ${result.error.message}`);
}
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error adding dependency');
} catch (error) {
log.error(`Error in addDependency tool: ${error.message}`);
return createErrorResponse(error.message);
}
},
});
}

View File

@@ -872,7 +872,7 @@ Implement the addTemplates function in the MCP server's index.js file to enable
### Details:
Analyze and refactor the project root handling mechanism to ensure consistent file path resolution across all MCP direct functions. This should properly handle relative and absolute paths, respect the projectRoot parameter when provided, and have appropriate fallbacks when not specified. Document the approach in a comment within path-utils.js for future maintainers.
## 39. Implement add-dependency MCP command [in-progress]
## 39. Implement add-dependency MCP command [done]
### Dependencies: 23.31
### Description: Create MCP tool implementation for the add-dependency command
### Details:

View File

@@ -1701,7 +1701,7 @@
"title": "Implement add-dependency MCP command",
"description": "Create MCP tool implementation for the add-dependency command",
"details": "",
"status": "in-progress",
"status": "done",
"dependencies": [
"23.31"
],