* wip: replace tool parameter inputs with root directory paths * fix: moved path resolving responsibility to tools - made path in parameters to optional for AI - internalised path resolving using session roots * chore: update package-lock.json * chore: fix regressions and fix CI * fix: make projectRoot required * fix: add-task tool * fix: updateTask tool * fix: remove reportProgress * chore: cleanup * fix: expand-task tool * chore: remove usless logs * fix: dependency manager logging in mcp server
77 lines
2.1 KiB
JavaScript
77 lines
2.1 KiB
JavaScript
/**
|
|
* tools/fix-dependencies.js
|
|
* Tool for automatically fixing invalid task dependencies
|
|
*/
|
|
|
|
import { z } from 'zod';
|
|
import {
|
|
handleApiResult,
|
|
createErrorResponse,
|
|
getProjectRootFromSession
|
|
} from './utils.js';
|
|
import { fixDependenciesDirect } from '../core/task-master-core.js';
|
|
import { findTasksJsonPath } from '../core/utils/path-utils.js';
|
|
|
|
/**
|
|
* Register the fixDependencies tool with the MCP server
|
|
* @param {Object} server - FastMCP server instance
|
|
*/
|
|
export function registerFixDependenciesTool(server) {
|
|
server.addTool({
|
|
name: 'fix_dependencies',
|
|
description: 'Fix invalid dependencies in tasks automatically',
|
|
parameters: z.object({
|
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
|
projectRoot: z
|
|
.string()
|
|
.describe('The directory of the project. Must be an absolute path.')
|
|
}),
|
|
execute: async (args, { log, session }) => {
|
|
try {
|
|
log.info(`Fixing dependencies with args: ${JSON.stringify(args)}`);
|
|
|
|
// Get project root from args or session
|
|
const rootFolder =
|
|
args.projectRoot || getProjectRootFromSession(session, log);
|
|
|
|
if (!rootFolder) {
|
|
return createErrorResponse(
|
|
'Could not determine project root. Please provide it explicitly or ensure your session contains valid root information.'
|
|
);
|
|
}
|
|
|
|
let tasksJsonPath;
|
|
try {
|
|
tasksJsonPath = findTasksJsonPath(
|
|
{ projectRoot: rootFolder, file: args.file },
|
|
log
|
|
);
|
|
} catch (error) {
|
|
log.error(`Error finding tasks.json: ${error.message}`);
|
|
return createErrorResponse(
|
|
`Failed to find tasks.json: ${error.message}`
|
|
);
|
|
}
|
|
|
|
const result = await fixDependenciesDirect(
|
|
{
|
|
tasksJsonPath: tasksJsonPath
|
|
},
|
|
log
|
|
);
|
|
|
|
if (result.success) {
|
|
log.info(`Successfully fixed dependencies: ${result.data.message}`);
|
|
} else {
|
|
log.error(`Failed to fix dependencies: ${result.error.message}`);
|
|
}
|
|
|
|
return handleApiResult(result, log, 'Error fixing dependencies');
|
|
} catch (error) {
|
|
log.error(`Error in fixDependencies tool: ${error.message}`);
|
|
return createErrorResponse(error.message);
|
|
}
|
|
}
|
|
});
|
|
}
|