fix(mcp): make projectRoot optional in all MCP tools
- Update all tool definitions to use z.string().optional() for projectRoot - Fix direct function implementations to use findTasksJsonPath(args, log) pattern - Enables consistent project root detection without requiring explicit params - Update changeset to document these improvements This change ensures MCP tools work properly with the smart project root detection system, removing the need for explicit projectRoot parameters in client applications. Improves usability and reduces integration friction.
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
- Parent directory traversal to find tasks.json
|
||||
- Package directory as fallback
|
||||
|
||||
- Updated all MCP tools to work without explicitly requiring project root:
|
||||
- Changed all tool definitions from `projectRoot: z.string().describe(...)` to `projectRoot: z.string().optional().describe(...)`
|
||||
- Updated all direct function implementations from `findTasksJsonPath(args.file, args.projectRoot)` to use the proper `findTasksJsonPath(args, log)` pattern
|
||||
- These changes allow MCP tools to work properly without requiring the projectRoot parameter, using smart detection to automatically determine the project root
|
||||
|
||||
- Add comprehensive PROJECT_MARKERS array for detecting common project files:
|
||||
- Task Master specific files (tasks.json, tasks/tasks.json)
|
||||
- Version control markers (.git, .svn)
|
||||
|
||||
@@ -47,7 +47,7 @@ export async function addSubtaskDirect(args, log) {
|
||||
}
|
||||
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Parse dependencies if provided
|
||||
let dependencies = [];
|
||||
|
||||
@@ -20,8 +20,8 @@ import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||
*/
|
||||
export async function addTaskDirect(args, log) {
|
||||
try {
|
||||
// Resolve the tasks file path
|
||||
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Check required parameters
|
||||
if (!args.prompt) {
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function analyzeTaskComplexityDirect(args, log) {
|
||||
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Determine output path
|
||||
let outputPath = args.output || 'scripts/task-complexity-report.json';
|
||||
|
||||
@@ -32,7 +32,7 @@ export async function clearSubtasksDirect(args, log) {
|
||||
}
|
||||
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Check if tasks.json exists
|
||||
if (!fs.existsSync(tasksPath)) {
|
||||
|
||||
@@ -22,7 +22,7 @@ export async function expandAllTasksDirect(args, log) {
|
||||
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
|
||||
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Parse parameters
|
||||
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
|
||||
|
||||
@@ -18,8 +18,8 @@ export async function fixDependenciesDirect(args, log) {
|
||||
try {
|
||||
log.info(`Fixing invalid dependencies in tasks...`);
|
||||
|
||||
// Determine the tasks file path
|
||||
const tasksPath = args.file || await findTasksJsonPath(args.projectRoot);
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Verify the file exists
|
||||
if (!fs.existsSync(tasksPath)) {
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function removeDependencyDirect(args, log) {
|
||||
}
|
||||
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
|
||||
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);
|
||||
|
||||
@@ -42,7 +42,7 @@ export async function removeSubtaskDirect(args, log) {
|
||||
}
|
||||
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args.file, args.projectRoot);
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Convert convertToTask to a boolean
|
||||
const convertToTask = args.convert === true;
|
||||
|
||||
@@ -18,8 +18,8 @@ export async function validateDependenciesDirect(args, log) {
|
||||
try {
|
||||
log.info(`Validating dependencies in tasks...`);
|
||||
|
||||
// Determine the tasks file path
|
||||
const tasksPath = args.file || await findTasksJsonPath(args.projectRoot);
|
||||
// Find the tasks.json path
|
||||
const tasksPath = findTasksJsonPath(args, log);
|
||||
|
||||
// Verify the file exists
|
||||
if (!fs.existsSync(tasksPath)) {
|
||||
|
||||
@@ -22,7 +22,7 @@ export function registerAddDependencyTool(server) {
|
||||
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().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -28,7 +28,7 @@ export function registerAddSubtaskTool(server) {
|
||||
dependencies: z.string().optional().describe("Comma-separated list of dependency IDs for the new subtask"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
|
||||
projectRoot: z.string().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -23,7 +23,7 @@ export function registerAddTaskTool(server) {
|
||||
dependencies: z.string().optional().describe("Comma-separated list of task IDs this task depends on"),
|
||||
priority: z.string().optional().describe("Task priority (high, medium, low)"),
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z.string().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async ({ prompt, dependencies, priority, file, projectRoot }, log) => {
|
||||
try {
|
||||
|
||||
@@ -24,7 +24,7 @@ export function registerAnalyzeTool(server) {
|
||||
threshold: z.union([z.number(), z.string()]).optional().describe("Minimum complexity score to recommend expansion (1-10) (default: 5)"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed complexity analysis"),
|
||||
projectRoot: z.string().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -22,7 +22,7 @@ export function registerClearSubtasksTool(server) {
|
||||
id: z.string().optional().describe("Task IDs (comma-separated) to clear subtasks from"),
|
||||
all: z.boolean().optional().describe("Clear subtasks from all tasks"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
projectRoot: z.string().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}).refine(data => data.id || data.all, {
|
||||
message: "Either 'id' or 'all' parameter must be provided",
|
||||
path: ["id", "all"]
|
||||
|
||||
@@ -20,7 +20,7 @@ export function registerComplexityReportTool(server) {
|
||||
description: "Display the complexity analysis report in a readable format",
|
||||
parameters: z.object({
|
||||
file: z.string().optional().describe("Path to the report file (default: scripts/task-complexity-report.json)"),
|
||||
projectRoot: z.string().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -24,7 +24,7 @@ export function registerExpandAllTool(server) {
|
||||
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().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -20,7 +20,7 @@ export function registerFixDependenciesTool(server) {
|
||||
description: "Fix invalid dependencies in tasks automatically",
|
||||
parameters: z.object({
|
||||
file: z.string().optional().describe("Path to the tasks file"),
|
||||
projectRoot: z.string().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -22,7 +22,7 @@ export function registerRemoveDependencyTool(server) {
|
||||
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().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -23,7 +23,7 @@ export function registerRemoveSubtaskTool(server) {
|
||||
convert: z.boolean().optional().describe("Convert the subtask to a standalone task instead of deleting it"),
|
||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
||||
skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
|
||||
projectRoot: z.string().describe("Root directory of the project (default: current working directory)")
|
||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async (args, { log }) => {
|
||||
try {
|
||||
|
||||
@@ -1207,9 +1207,3 @@ This method provides a consistent way to access environment variables defined in
|
||||
### Details:
|
||||
|
||||
|
||||
## 47. adjust rules so it prioritizes mcp commands over script [pending]
|
||||
### Dependencies: None
|
||||
### Description:
|
||||
### Details:
|
||||
|
||||
|
||||
|
||||
@@ -1780,15 +1780,6 @@
|
||||
"status": "pending",
|
||||
"dependencies": [],
|
||||
"parentTaskId": 23
|
||||
},
|
||||
{
|
||||
"id": 47,
|
||||
"title": "adjust rules so it prioritizes mcp commands over script",
|
||||
"description": "",
|
||||
"details": "",
|
||||
"status": "pending",
|
||||
"dependencies": [],
|
||||
"parentTaskId": 23
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user