feat: implement add-task MCP command
- Create direct function wrapper in add-task.js with prompt and dependency handling - Add MCP tool integration for creating new tasks via AI - Update task-master-core.js to expose addTaskDirect function - Update changeset to document the new command
This commit is contained in:
47
mcp-server/src/tools/add-task.js
Normal file
47
mcp-server/src/tools/add-task.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* tools/add-task.js
|
||||
* Tool to add a new task using AI
|
||||
*/
|
||||
|
||||
import { z } from "zod";
|
||||
import {
|
||||
handleApiResult,
|
||||
createErrorResponse
|
||||
} from "./utils.js";
|
||||
import { addTaskDirect } from "../core/task-master-core.js";
|
||||
|
||||
/**
|
||||
* Register the add-task tool with the MCP server
|
||||
* @param {Object} server - FastMCP server instance
|
||||
*/
|
||||
export function registerAddTaskTool(server) {
|
||||
server.addTool({
|
||||
name: "add_task",
|
||||
description: "Add a new task using AI",
|
||||
parameters: z.object({
|
||||
prompt: z.string().describe("Description of the task to add"),
|
||||
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().optional().describe("Root directory of the project (default: current working directory)")
|
||||
}),
|
||||
execute: async ({ prompt, dependencies, priority, file, projectRoot }, log) => {
|
||||
try {
|
||||
log.info(`MCP add_task called with prompt: "${prompt}"`);
|
||||
|
||||
const result = await addTaskDirect({
|
||||
prompt,
|
||||
dependencies,
|
||||
priority,
|
||||
file,
|
||||
projectRoot
|
||||
}, log);
|
||||
|
||||
return handleApiResult(result);
|
||||
} catch (error) {
|
||||
log.error(`Error in add_task MCP tool: ${error.message}`);
|
||||
return createErrorResponse(error.message, "ADD_TASK_ERROR");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { registerGenerateTool } from "./generate.js";
|
||||
import { registerShowTaskTool } from "./show-task.js";
|
||||
import { registerNextTaskTool } from "./next-task.js";
|
||||
import { registerExpandTaskTool } from "./expand-task.js";
|
||||
import { registerAddTaskTool } from "./add-task.js";
|
||||
|
||||
/**
|
||||
* Register all Task Master tools with the MCP server
|
||||
@@ -30,6 +31,9 @@ export function registerTaskMasterTools(server) {
|
||||
registerShowTaskTool(server);
|
||||
registerNextTaskTool(server);
|
||||
registerExpandTaskTool(server);
|
||||
registerAddTaskTool(server);
|
||||
|
||||
logger.info("Registered all Task Master tools with MCP server");
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user