check_response_status
Monitor the progress of AI response generation tasks to track completion status and retrieve results when ready.
Instructions
Check the status of a response generation task
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| taskId | Yes | The task ID returned by generate_response |
Implementation Reference
- src/index.ts:402-501 (handler)The handler logic for the 'check_response_status' tool within the CallToolRequestSchema request handler. It validates input, retrieves the task status from activeTasks map, checks for timeouts and maximum check attempts, implements exponential backoff for polling delays, updates task metadata, and returns the current status, reasoning/response if available, error if any, and suggested next check interval.} else if (request.params.name === "check_response_status") { if (!isValidCheckResponseStatusArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, "Invalid check_response_status arguments" ); } const taskId = request.params.arguments.taskId; const task = this.activeTasks.get(taskId); if (!task) { throw new McpError( ErrorCode.InvalidRequest, `No task found with ID: ${taskId}` ); } // Vérifier si la tâche a expiré const currentTime = Date.now(); if (currentTime - task.timestamp > TASK_TIMEOUT_MS) { const updatedTask = { ...task, status: "error" as const, error: `Tâche expirée après ${TASK_TIMEOUT_MS / 60000} minutes` }; this.activeTasks.set(taskId, updatedTask); return { content: [ { type: "text", text: JSON.stringify({ status: updatedTask.status, reasoning: updatedTask.showReasoning ? updatedTask.reasoning : undefined, response: undefined, error: updatedTask.error, timeoutAfter: TASK_TIMEOUT_MS / 60000 }) } ] }; } // Mettre à jour les propriétés de suivi const checkAttempts = (task.checkAttempts || 0) + 1; // Vérifier si nous avons atteint le nombre maximal de tentatives if (checkAttempts > MAX_STATUS_CHECK_ATTEMPTS && task.status !== "complete" && task.status !== "error") { const updatedTask = { ...task, status: "error" as const, error: `Nombre maximum de tentatives atteint (${MAX_STATUS_CHECK_ATTEMPTS})`, checkAttempts }; this.activeTasks.set(taskId, updatedTask); return { content: [ { type: "text", text: JSON.stringify({ status: updatedTask.status, reasoning: updatedTask.showReasoning ? updatedTask.reasoning : undefined, response: undefined, error: updatedTask.error, maxAttempts: MAX_STATUS_CHECK_ATTEMPTS }) } ] }; } // Calculer le délai avant la prochaine vérification (backoff exponentiel) let nextCheckDelay = task.nextCheckDelay || INITIAL_STATUS_CHECK_DELAY_MS; nextCheckDelay = Math.min(nextCheckDelay * STATUS_CHECK_BACKOFF_FACTOR, MAX_STATUS_CHECK_DELAY_MS); // Mettre à jour le statut de la tâche const updatedTask = { ...task, lastChecked: currentTime, nextCheckDelay, checkAttempts }; this.activeTasks.set(taskId, updatedTask); return { content: [ { type: "text", text: JSON.stringify({ status: task.status, reasoning: task.showReasoning ? task.reasoning : undefined, response: task.status === "complete" ? task.response : undefined, error: task.error, nextCheckIn: Math.round(nextCheckDelay / 1000), // Temps suggéré en secondes checkAttempts, elapsedTime: Math.round((currentTime - task.timestamp) / 1000) // Temps écoulé en secondes }), }, ], };
- src/index.ts:337-350 (registration)Registration of the 'check_response_status' tool in the server's listTools response, specifying name, description, and input schema.{ name: "check_response_status", description: "Check the status of a response generation task", inputSchema: { type: "object", properties: { taskId: { type: "string", description: "The task ID returned by generate_response", }, }, required: ["taskId"], }, },
- src/index.ts:61-63 (schema)TypeScript interface defining the input schema for check_response_status arguments.interface CheckResponseStatusArgs { taskId: string; }
- src/index.ts:79-82 (helper)Helper function for validating check_response_status arguments against the CheckResponseStatusArgs interface.const isValidCheckResponseStatusArgs = ( args: any ): args is CheckResponseStatusArgs => typeof args === "object" && args !== null && typeof args.taskId === "string";
- src/index.ts:65-77 (schema)TypeScript interface defining the TaskStatus structure used by the check_response_status handler for tracking and returning task state.interface TaskStatus { status: "pending" | "reasoning" | "responding" | "complete" | "error"; prompt: string; showReasoning?: boolean; reasoning?: string; response?: string; error?: string; timestamp: number; // Nouvelles propriétés pour gérer le polling lastChecked?: number; nextCheckDelay?: number; checkAttempts?: number; }