fix: add rest of tools that need wrapper

This commit is contained in:
Ralph Khreish
2025-05-02 19:56:13 +02:00
parent d18351dc38
commit 8f8a3dc45d
4 changed files with 25 additions and 40 deletions

View File

@@ -1,5 +1,9 @@
import { z } from 'zod';
import { createErrorResponse, handleApiResult } from './utils.js';
import {
createErrorResponse,
handleApiResult,
withNormalizedProjectRoot
} from './utils.js';
import { initializeProjectDirect } from '../core/task-master-core.js';
export function registerInitializeProjectTool(server) {
@@ -33,19 +37,10 @@ export function registerInitializeProjectTool(server) {
'The root directory for the project. ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY. IF NOT SET, THE TOOL WILL NOT WORK.'
)
}),
execute: async (args, context) => {
execute: withNormalizedProjectRoot(async (args, context) => {
const { log } = context;
const session = context.session;
log.info(
'>>> Full Context Received by Tool:',
JSON.stringify(context, null, 2)
);
log.info(`Context received in tool function: ${context}`);
log.info(
`Session received in tool function: ${session ? session : 'undefined'}`
);
try {
log.info(
`Executing initialize_project tool with args: ${JSON.stringify(args)}`
@@ -59,6 +54,6 @@ export function registerInitializeProjectTool(server) {
log.error(errorMessage, error);
return createErrorResponse(errorMessage, { details: error.stack });
}
}
})
});
}

View File

@@ -5,7 +5,11 @@
import { z } from 'zod';
import path from 'path';
import { handleApiResult, createErrorResponse } from './utils.js';
import {
handleApiResult,
createErrorResponse,
withNormalizedProjectRoot
} from './utils.js';
import { parsePRDDirect } from '../core/task-master-core.js';
/**
@@ -49,7 +53,7 @@ export function registerParsePRDTool(server) {
.string()
.describe('The directory of the project. Must be an absolute path.')
}),
execute: async (args, { log, session }) => {
execute: withNormalizedProjectRoot(async (args, { log, session }) => {
const toolName = 'parse_prd';
try {
log.info(
@@ -97,6 +101,6 @@ export function registerParsePRDTool(server) {
`Internal tool error (${toolName}): ${error.message}`
);
}
}
})
});
}

View File

@@ -8,6 +8,7 @@ import { handleApiResult, createErrorResponse } from './utils.js';
import { updateSubtaskByIdDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
import path from 'path';
import { withNormalizedProjectRoot } from '../core/utils/project-utils.js';
/**
* Register the update-subtask tool with the MCP server
@@ -34,7 +35,7 @@ export function registerUpdateSubtaskTool(server) {
.string()
.describe('The directory of the project. Must be an absolute path.')
}),
execute: async (args, { log, session }) => {
execute: withNormalizedProjectRoot(async (args, { log, session }) => {
const toolName = 'update_subtask';
try {
log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
@@ -95,6 +96,6 @@ export function registerUpdateSubtaskTool(server) {
`Internal tool error (${toolName}): ${error.message}`
);
}
}
})
});
}

View File

@@ -4,11 +4,10 @@
*/
import { z } from 'zod';
import path from 'path'; // Import path
import {
handleApiResult,
createErrorResponse,
getProjectRootFromSession
withNormalizedProjectRoot
} from './utils.js';
import { updateTaskByIdDirect } from '../core/task-master-core.js';
import { findTasksJsonPath } from '../core/utils/path-utils.js';
@@ -40,58 +39,44 @@ export function registerUpdateTaskTool(server) {
.string()
.describe('The directory of the project. Must be an absolute path.')
}),
execute: async (args, { log, session }) => {
execute: withNormalizedProjectRoot(async (args, { log, session }) => {
const toolName = 'update_task';
try {
log.info(
`Executing ${toolName} tool with args: ${JSON.stringify(args)}`
);
// 1. Get Project Root
const rootFolder = args.projectRoot;
if (!rootFolder || !path.isAbsolute(rootFolder)) {
log.error(
`${toolName}: projectRoot is required and must be absolute.`
);
return createErrorResponse(
'projectRoot is required and must be absolute.'
);
}
log.info(`${toolName}: Project root: ${rootFolder}`);
// 2. Resolve Tasks Path
let tasksJsonPath;
try {
tasksJsonPath = findTasksJsonPath(
{ projectRoot: rootFolder, file: args.file }, // Pass root and optional relative file
{ projectRoot: args.projectRoot, file: args.file },
log
);
log.info(`${toolName}: Resolved tasks path: ${tasksJsonPath}`);
} catch (error) {
log.error(`${toolName}: Error finding tasks.json: ${error.message}`);
return createErrorResponse(
`Failed to find tasks.json within project root '${rootFolder}': ${error.message}`
`Failed to find tasks.json: ${error.message}`
);
}
// 3. Call Direct Function - Include projectRoot
const result = await updateTaskByIdDirect(
{
tasksJsonPath: tasksJsonPath, // Pass resolved path
tasksJsonPath: tasksJsonPath,
id: args.id,
prompt: args.prompt,
research: args.research,
projectRoot: rootFolder // <<< Pass projectRoot HERE
projectRoot: args.projectRoot
},
log,
{ session } // Pass context with session
{ session }
);
// 4. Handle Result
log.info(
`${toolName}: Direct function result: success=${result.success}`
);
// Pass the actual data from the result (contains updated task or message)
return handleApiResult(result, log, 'Error updating task');
} catch (error) {
log.error(
@@ -101,6 +86,6 @@ export function registerUpdateTaskTool(server) {
`Internal tool error (${toolName}): ${error.message}`
);
}
}
})
});
}