Skip to main content
Glama

taskGetById

Retrieve a specific task by its unique ID to access detailed information and manage task-related operations within the GonMCPtool server.

Instructions

根據ID獲取特定任務

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes

Implementation Reference

  • main.ts:622-644 (registration)
    Registration of the taskGetById MCP tool, including input schema { id: z.string() } and thin wrapper handler that calls the core TaskManagerTool.getTaskById method and formats the 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 : "未知錯誤"}` }] }; } } );
  • Core implementation of task retrieval by ID: reads all tasks from JSON file and finds the matching task using Array.find.
    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; }
  • TypeScript interface defining the Task object structure, used for type safety in input/output of the tool.
    export interface Task { /** * 任務唯一識別碼 */ id: string; /** * 任務標題 */ title: string; /** * 任務詳細描述 */ description: string; /** * 任務步驟列表 */ steps: TaskStep[]; /** * 任務標籤列表 */ tags: string[]; /** * 任務建立時間 */ createdAt: string; /** * 任務更新時間 */ updatedAt: string; /** * 任務期限時間 */ dueDate?: string; /** * 預計開始時間 */ plannedStartDate?: string; /** * 實際開始時間 */ actualStartDate?: string; /** * 實際完成時間 */ actualCompletionDate?: string; /** * 任務狀態 */ status: TaskStatus; /** * 任務優先級 (1-5, 1為最高) */ priority: number; }
  • Helper method to read all tasks from the persistent JSON storage file (./task/tasks.json). Called 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 : '未知錯誤'}`); } }

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