diff --git a/.changeset/two-bats-smoke.md b/.changeset/two-bats-smoke.md index 44272dd0..1cc69f92 100644 --- a/.changeset/two-bats-smoke.md +++ b/.changeset/two-bats-smoke.md @@ -7,4 +7,5 @@ - Implement update-subtask MCP command for appending information to specific subtasks - Implement generate MCP command for creating individual task files from tasks.json - Implement set-status MCP command for updating task status +- Implement show-task MCP command for displaying detailed task information - 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) diff --git a/mcp-server/src/core/direct-functions/show-task.js b/mcp-server/src/core/direct-functions/show-task.js new file mode 100644 index 00000000..c2e09962 --- /dev/null +++ b/mcp-server/src/core/direct-functions/show-task.js @@ -0,0 +1,125 @@ +/** + * show-task.js + * Direct function implementation for showing task details + */ + +import { findTaskById } from '../../../../scripts/modules/utils.js'; +import { readJSON } from '../../../../scripts/modules/utils.js'; +import { getCachedOrExecute } from '../../tools/utils.js'; +import { findTasksJsonPath } from '../utils/path-utils.js'; + +/** + * Direct function wrapper for showing task details with error handling and caching. + * + * @param {Object} args - Command arguments + * @param {Object} log - Logger object + * @returns {Promise} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean } + */ +export async function showTaskDirect(args, log) { + let tasksPath; + try { + // Find the tasks path first - needed for cache key and execution + tasksPath = findTasksJsonPath(args, log); + } catch (error) { + log.error(`Tasks file not found: ${error.message}`); + return { + success: false, + error: { + code: 'FILE_NOT_FOUND_ERROR', + message: error.message + }, + fromCache: false + }; + } + + // Validate task ID + const taskId = args.id; + if (!taskId) { + log.error('Task ID is required'); + return { + success: false, + error: { + code: 'INPUT_VALIDATION_ERROR', + message: 'Task ID is required' + }, + fromCache: false + }; + } + + // Generate cache key using task path and ID + const cacheKey = `showTask:${tasksPath}:${taskId}`; + + // Define the action function to be executed on cache miss + const coreShowTaskAction = async () => { + try { + log.info(`Retrieving task details for ID: ${taskId} from ${tasksPath}`); + + // Read tasks data + const data = readJSON(tasksPath); + if (!data || !data.tasks) { + return { + success: false, + error: { + code: 'INVALID_TASKS_FILE', + message: `No valid tasks found in ${tasksPath}` + } + }; + } + + // Find the specific task + const task = findTaskById(data.tasks, taskId); + + if (!task) { + return { + success: false, + error: { + code: 'TASK_NOT_FOUND', + message: `Task with ID ${taskId} not found` + } + }; + } + + // Return the task data with the full tasks array for reference + // (needed for formatDependenciesWithStatus function in UI) + log.info(`Successfully found task ${taskId}`); + return { + success: true, + data: { + task, + allTasks: data.tasks + } + }; + } catch (error) { + log.error(`Error showing task: ${error.message}`); + return { + success: false, + error: { + code: 'CORE_FUNCTION_ERROR', + message: error.message || 'Failed to show task details' + } + }; + } + }; + + // Use the caching utility + try { + const result = await getCachedOrExecute({ + cacheKey, + actionFn: coreShowTaskAction, + log + }); + log.info(`showTaskDirect completed. From cache: ${result.fromCache}`); + return result; // Returns { success, data/error, fromCache } + } catch (error) { + // Catch unexpected errors from getCachedOrExecute itself + log.error(`Unexpected error during getCachedOrExecute for showTask: ${error.message}`); + return { + success: false, + error: { + code: 'UNEXPECTED_ERROR', + message: error.message + }, + fromCache: false + }; + } +} \ No newline at end of file diff --git a/mcp-server/src/core/task-master-core.js b/mcp-server/src/core/task-master-core.js index 44f6ea60..14a24fe8 100644 --- a/mcp-server/src/core/task-master-core.js +++ b/mcp-server/src/core/task-master-core.js @@ -13,6 +13,7 @@ import { updateTaskByIdDirect } from './direct-functions/update-task-by-id.js'; import { updateSubtaskByIdDirect } from './direct-functions/update-subtask-by-id.js'; import { generateTaskFilesDirect } from './direct-functions/generate-task-files.js'; import { setTaskStatusDirect } from './direct-functions/set-task-status.js'; +import { showTaskDirect } from './direct-functions/show-task.js'; // Re-export utility functions export { findTasksJsonPath } from './utils/path-utils.js'; @@ -27,6 +28,7 @@ export { updateSubtaskByIdDirect, generateTaskFilesDirect, setTaskStatusDirect, + showTaskDirect, }; /** @@ -42,5 +44,6 @@ export const directFunctions = { updateSubtask: updateSubtaskByIdDirect, generate: generateTaskFilesDirect, setStatus: setTaskStatusDirect, + showTask: showTaskDirect, // Add more functions as we implement them }; \ No newline at end of file diff --git a/mcp-server/src/tools/index.js b/mcp-server/src/tools/index.js index faaafcf5..748530bd 100644 --- a/mcp-server/src/tools/index.js +++ b/mcp-server/src/tools/index.js @@ -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, -}; +}; \ No newline at end of file diff --git a/mcp-server/src/tools/show-task.js b/mcp-server/src/tools/show-task.js new file mode 100644 index 00000000..a29574b5 --- /dev/null +++ b/mcp-server/src/tools/show-task.js @@ -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}`); + } + }, + }); +} \ No newline at end of file diff --git a/tasks/task_023.txt b/tasks/task_023.txt index c519fec4..7bb5932c 100644 --- a/tasks/task_023.txt +++ b/tasks/task_023.txt @@ -505,7 +505,7 @@ Following MCP implementation standards: - Unit test for setTaskStatusDirect.js - Integration test for MCP tool -## 22. Implement show-task MCP command [pending] +## 22. Implement show-task MCP command [in-progress] ### Dependencies: None ### Description: Create direct function wrapper and MCP tool for showing task details. ### Details: diff --git a/tasks/tasks.json b/tasks/tasks.json index 8c0735a5..6c2050e2 100644 --- a/tasks/tasks.json +++ b/tasks/tasks.json @@ -1546,7 +1546,7 @@ "title": "Implement show-task MCP command", "description": "Create direct function wrapper and MCP tool for showing task details.", "details": "Following MCP implementation standards:\n\n1. Create showTaskDirect.js in mcp-server/src/core/direct-functions/:\n - Import showTask from task-manager.js\n - Handle file paths using findTasksJsonPath utility\n - Process arguments: taskId\n - Validate inputs and handle errors with try/catch\n - Return standardized { success, data/error } object\n\n2. Export from task-master-core.js:\n - Import the function from its file\n - Add to directFunctions map\n\n3. Create show-task.js MCP tool in mcp-server/src/tools/:\n - Import z from zod for parameter schema\n - Import executeMCPToolAction from ./utils.js\n - Import showTaskDirect from task-master-core.js\n - Define parameters matching CLI options using zod schema\n - Implement registerShowTaskTool(server) with server.addTool\n - Use executeMCPToolAction in execute method\n\n4. Register in tools/index.js with tool name 'show_task'\n\n5. Add to .cursor/mcp.json with appropriate schema\n\n6. Write tests following testing guidelines:\n - Unit test for showTaskDirect.js\n - Integration test for MCP tool", - "status": "pending", + "status": "in-progress", "dependencies": [], "parentTaskId": 23 },