get_task_result
Retrieve the final output of a completed AI task by providing its task ID. Designed for managing asynchronous workflows on the MCP Task server.
Instructions
Get the final result of a completed task.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task_id | Yes | The task ID returned from run_task |
Implementation Reference
- src/serve.ts:706-734 (handler)The main handler logic for the 'get_task_result' tool. It validates the task_id, retrieves the task using TaskManager.getTask(), checks if it's completed/failed/cancelled, and returns the task.output.case 'get_task_result': { if (!args.task_id) { throw new Error('task_id is required'); } const task = taskManager.getTask(args.task_id); if (!task) { throw new Error(`Task ${args.task_id} not found`); } if ( task.status !== 'completed' && task.status !== 'failed' && task.status !== 'cancelled' ) { throw new Error( `Task ${args.task_id} is not complete. Status: ${task.status}` ); } return { content: [ { type: 'text', text: task.output || 'No output available', }, ], }; }
- src/serve.ts:194-214 (schema)The Tool schema definition including name, description, annotations, and inputSchema for 'get_task_result'.const GET_TASK_RESULT_TOOL: Tool = { name: 'get_task_result', description: 'Get the final result of a completed task.', annotations: { title: 'Get Task Result', readOnlyHint: true, // Only reads completed task result destructiveHint: false, // Doesn't modify or destroy data idempotentHint: false, // task_id returns result each time openWorldHint: false, // Only queries local task state }, inputSchema: { type: 'object', properties: { task_id: { type: 'string', description: 'The task ID returned from run_task', }, }, required: ['task_id'], }, };
- src/serve.ts:558-579 (registration)Registration of the tool via the ListToolsRequestSchema handler, which returns the list of available tools including 'get_task_result'.server.setRequestHandler(ListToolsRequestSchema, async () => { if (process.env.MCP_MODE !== 'true') { logger.debug('Received ListTools request'); } const response = { tools: [ RUN_TASK_TOOL, CHECK_TASK_STATUS_TOOL, GET_TASK_RESULT_TOOL, CANCEL_TASK_TOOL, WAIT_FOR_TASK_TOOL, LIST_TASKS_TOOL, ], }; if (process.env.MCP_MODE !== 'true') { logger.debug( 'Returning tools:', response.tools.map(t => t.name) ); } return response; });
- src/utils/task-manager.ts:261-263 (helper)Core helper method TaskManager.getTask() used by the handler to retrieve task information by ID.public getTask(taskId: string): TaskInfo | undefined { return this.tasks.get(taskId); }