taskCreate
Create structured tasks with multiple steps, including titles, descriptions, priorities, due dates, and tags for organized project management.
Instructions
創建新的任務,可以包含多個步驟
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| description | Yes | ||
| steps | Yes | ||
| tags | No | ||
| dueDate | No | ||
| priority | No |
Implementation Reference
- tools/taskManagerTool.ts:79-128 (handler)Core handler function that implements the task creation logic: validates inputs, generates UUIDs for task and steps, reads existing tasks from JSON, appends new task, and persists back to file.public static async createTask( title: string, description: string, steps: Omit<TaskStep, 'id'>[], tags: string[] = [], dueDate?: string, plannedStartDate?: string, priority: number = 3 ): Promise<Task> { if (!title || !description) { throw new Error('任務標題和描述不能為空'); } if (priority < 1 || priority > 5) { throw new Error('任務優先級必須在1到5之間'); } // 獲取現有任務 const tasks = await this.readTasks(); // 創建新任務 const now = new Date().toISOString(); const taskSteps = steps.map((step, index) => ({ ...step, id: uuidv4(), order: step.order !== undefined ? step.order : index + 1, completed: step.completed !== undefined ? step.completed : false })); const newTask: Task = { id: uuidv4(), title, description, steps: taskSteps, tags, createdAt: now, plannedStartDate, updatedAt: now, status: TaskStatus.PENDING, priority }; // 添加新任務 tasks.push(newTask); // 保存所有任務 await this.writeTasks(tasks); return newTask; }
- main.ts:568-579 (schema)Zod schema defining the input parameters for the taskCreate tool.title: z.string(), description: z.string(), steps: z.array(z.object({ description: z.string(), order: z.number().optional(), completed: z.boolean().optional(), estimatedTime: z.number().optional() })), tags: z.array(z.string()).optional(), dueDate: z.string().optional(), priority: z.number().optional() },
- main.ts:565-600 (registration)MCP server registration of the 'taskCreate' tool, including description, schema, and thin wrapper handler that delegates to TaskManagerTool.createTask.server.tool("taskCreate", "創建新的任務,可以包含多個步驟", { title: z.string(), description: z.string(), steps: z.array(z.object({ description: z.string(), order: z.number().optional(), completed: z.boolean().optional(), estimatedTime: z.number().optional() })), tags: z.array(z.string()).optional(), dueDate: z.string().optional(), priority: z.number().optional() }, async ({ title, description, steps, tags = [], dueDate, priority = 3 }) => { try { const newTask = await TaskManagerTool.createTask( title, description, steps, tags, dueDate, String(priority) ); return { content: [{ type: "text", text: `任務創建成功:\n${JSON.stringify(newTask, null, 2)}` }] }; } catch (error) { return { content: [{ type: "text", text: `創建任務失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );