taskGetById
Retrieve specific task details by ID to enhance task management and streamline workflows within the GonMCPtool MCP server.
Instructions
根據ID獲取特定任務
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes |
Implementation Reference
- main.ts:622-644 (registration)Registration of the 'taskGetById' tool including description, Zod input schema {id: z.string()}, and handler function that retrieves the task via TaskManagerTool and formats response.server.tool("taskGetById", "根據ID獲取特定任務", { id: z.string() }, async ({ id }) => { try { const task = await TaskManagerTool.getTaskById(id); if (!task) { return { content: [{ type: "text", text: `未找到ID為 ${id} 的任務` }] }; } return { content: [{ type: "text", text: `任務詳情:\n${JSON.stringify(task, null, 2)}` }] }; } catch (error) { return { content: [{ type: "text", text: `獲取任務失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }] }; } } );
- tools/taskManagerTool.ts:140-144 (handler)Core handler logic for retrieving a task by ID: loads tasks from JSON storage and returns the matching task or null.public static async getTaskById(id: string): Promise<Task | null> { const tasks = await this.readTasks(); const task = tasks.find(t => t.id === id); return task || null; }
- main.ts:624-624 (schema)Input schema validation using Zod for the task ID parameter.{ id: z.string() },
- tools/taskManagerTool.ts:47-59 (helper)Helper function to read all tasks from the JSON file './task/tasks.json', used by getTaskById.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 : '未知錯誤'}`); } }