Skip to main content
Glama

taskStepAdd

Add a new step to an existing task by specifying the task ID and step description, with optional ordering and time estimation.

Instructions

為任務添加新步驟

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskIdYes
descriptionYes
orderNo
estimatedTimeNo

Implementation Reference

  • Core handler implementation for adding a new task step. Loads tasks from JSON file, finds the target task, creates new step with UUID and order, appends it, sorts steps by order, updates timestamp, and persists changes back to JSON.
    public static async addTaskStep( taskId: string, description: string, order?: number, estimatedTime?: number ): Promise<Task | null> { const tasks = await this.readTasks(); const taskIndex = tasks.findIndex(t => t.id === taskId); if (taskIndex === -1) { return null; } const task = tasks[taskIndex]; // 確定步驟順序 const newOrder = order || task.steps.length + 1; // 創建新步驟 const newStep: TaskStep = { id: uuidv4(), description, completed: false, order: newOrder, estimatedTime }; // 添加新步驟 task.steps.push(newStep); // 重新排序步驟 task.steps.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)); // 更新任務 task.updatedAt = new Date().toISOString(); // 保存所有任務 await this.writeTasks(tasks); return task; }
  • main.ts:746-773 (registration)
    MCP tool registration for 'taskStepAdd', including input schema (Zod) and thin async handler wrapper that delegates to TaskManagerTool.addTaskStep and formats response.
    server.tool("taskStepAdd", "為任務添加新步驟", { taskId: z.string(), description: z.string(), order: z.number().optional(), estimatedTime: z.number().optional() }, async ({ taskId, description, order, estimatedTime }) => { try { const updatedTask = await TaskManagerTool.addTaskStep(taskId, description, order, estimatedTime); if (!updatedTask) { return { content: [{ type: "text", text: `未找到ID為 ${taskId} 的任務` }] }; } return { content: [{ type: "text", text: `步驟添加成功:\n${JSON.stringify(updatedTask, null, 2)}` }] }; } catch (error) { return { content: [{ type: "text", text: `添加步驟失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
  • TypeScript interface definition for TaskStep, used in the task data structure and matching the tool's input schema.
    export interface TaskStep { /** * 步驟ID */ id: string; /** * 步驟描述 */ description: string; /** * 步驟是否完成 */ completed?: boolean; /** * 步驟順序 */ order?: number; /** * 步驟預估完成時間(分鐘) */ estimatedTime?: number; }
  • Helper methods for reading and writing tasks to/from JSON file, used by the addTaskStep handler for persistence.
    private static async readTasks(): Promise<Task[]> { await this.ensureTasksDirectory(); try { const tasksFile = this.getTasksFilePath(); const fileContent = fs.readFileSync(tasksFile, 'utf-8'); const data = JSON.parse(fileContent); return data.tasks || []; } catch (error) { console.error('Error reading tasks:', error); throw new Error(`讀取任務失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); } } /** * 寫入所有任務 */ private static async writeTasks(tasks: Task[]): Promise<void> { await this.ensureTasksDirectory(); try { const tasksFile = this.getTasksFilePath(); fs.writeFileSync(tasksFile, JSON.stringify({ tasks }, null, 2)); } catch (error) { console.error('Error writing tasks:', error); throw new Error(`寫入任務失敗: ${error instanceof Error ? error.message : '未知錯誤'}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/GonTwVn/GonMCPtool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server