feat: implement show-task MCP command

- Create direct function wrapper in show-task.js with error handling and caching

- Add MCP tool integration for displaying detailed task information

- Update task-master-core.js to expose showTaskDirect function

- Update changeset to document the new command

- Follow kebab-case/camelCase/snake_case naming conventions
This commit is contained in:
Eyal Toledano
2025-03-31 11:57:23 -04:00
parent 9582c0a91f
commit 05950ef318
7 changed files with 187 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ import { registerUpdateTool } from "./update.js";
import { registerUpdateTaskTool } from "./update-task.js";
import { registerUpdateSubtaskTool } from "./update-subtask.js";
import { registerGenerateTool } from "./generate.js";
import { registerShowTaskTool } from "./show-task.js";
/**
* Register all Task Master tools with the MCP server
@@ -24,8 +25,9 @@ export function registerTaskMasterTools(server) {
registerUpdateTaskTool(server);
registerUpdateSubtaskTool(server);
registerGenerateTool(server);
registerShowTaskTool(server);
}
export default {
registerTaskMasterTools,
};
};

View File

@@ -0,0 +1,53 @@
/**
* tools/show-task.js
* Tool to show task details by ID
*/
import { z } from "zod";
import {
handleApiResult,
createErrorResponse
} from "./utils.js";
import { showTaskDirect } from "../core/task-master-core.js";
/**
* Register the show-task tool with the MCP server
* @param {Object} server - FastMCP server instance
*/
export function registerShowTaskTool(server) {
server.addTool({
name: "show_task",
description: "Display detailed information about a specific task",
parameters: z.object({
id: z.string().describe("Task ID to show"),
file: z.string().optional().describe("Path to the tasks file"),
projectRoot: z
.string()
.optional()
.describe(
"Root directory of the project (default: current working directory)"
),
}),
execute: async (args, { log }) => {
try {
log.info(`Showing task details for ID: ${args.id}`);
// Call the direct function wrapper
const result = await showTaskDirect(args, log);
// Log result
if (result.success) {
log.info(`Successfully retrieved task details for ID: ${args.id}${result.fromCache ? ' (from cache)' : ''}`);
} else {
log.error(`Failed to show task: ${result.error.message}`);
}
// Use handleApiResult to format the response
return handleApiResult(result, log, 'Error retrieving task details');
} catch (error) {
log.error(`Error in show-task tool: ${error.message}`);
return createErrorResponse(`Failed to show task: ${error.message}`);
}
},
});
}