wait-for-task
Monitor Meilisearch task completion by polling status with configurable timeout and interval settings.
Instructions
Wait for a specific task to complete
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| taskUid | Yes | Unique identifier of the task to wait for | |
| timeoutMs | No | Maximum time to wait in milliseconds (default: 5000) | |
| intervalMs | No | Polling interval in milliseconds (default: 500) |
Implementation Reference
- src/tools/task-tools.ts:134-167 (handler)The handler function polls the Meilisearch API for the task status at specified intervals until the task reaches a terminal state (succeeded, failed, canceled) or the timeout is reached. It returns the final task data or a timeout message.async ({ taskUid, timeoutMs = 5000, intervalMs = 500 }: WaitForTaskParams) => { try { const startTime = Date.now(); let taskCompleted = false; let taskData = null; while (!taskCompleted && (Date.now() - startTime < timeoutMs)) { // Fetch the current task status const response = await apiClient.get(`/tasks/${taskUid}`); taskData = response.data; // Check if the task has completed if (["succeeded", "failed", "canceled"].includes(taskData.status)) { taskCompleted = true; } else { // Wait for the polling interval await new Promise(resolve => setTimeout(resolve, intervalMs)); } } if (!taskCompleted) { return { content: [{ type: "text", text: `Task ${taskUid} did not complete within the timeout period of ${timeoutMs}ms` }], }; } return { content: [{ type: "text", text: JSON.stringify(taskData, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } );
- src/tools/task-tools.ts:129-133 (schema)Zod input schema defining the parameters for the wait-for-task tool: required taskUid and optional timeoutMs and intervalMs.{ taskUid: z.number().describe("Unique identifier of the task to wait for"), timeoutMs: z.number().min(0).optional().describe("Maximum time to wait in milliseconds (default: 5000)"), intervalMs: z.number().min(100).optional().describe("Polling interval in milliseconds (default: 500)"), },
- src/tools/task-tools.ts:126-168 (registration)Registers the 'wait-for-task' tool on the MCP server within the registerTaskTools function.server.tool( "wait-for-task", "Wait for a specific task to complete", { taskUid: z.number().describe("Unique identifier of the task to wait for"), timeoutMs: z.number().min(0).optional().describe("Maximum time to wait in milliseconds (default: 5000)"), intervalMs: z.number().min(100).optional().describe("Polling interval in milliseconds (default: 500)"), }, async ({ taskUid, timeoutMs = 5000, intervalMs = 500 }: WaitForTaskParams) => { try { const startTime = Date.now(); let taskCompleted = false; let taskData = null; while (!taskCompleted && (Date.now() - startTime < timeoutMs)) { // Fetch the current task status const response = await apiClient.get(`/tasks/${taskUid}`); taskData = response.data; // Check if the task has completed if (["succeeded", "failed", "canceled"].includes(taskData.status)) { taskCompleted = true; } else { // Wait for the polling interval await new Promise(resolve => setTimeout(resolve, intervalMs)); } } if (!taskCompleted) { return { content: [{ type: "text", text: `Task ${taskUid} did not complete within the timeout period of ${timeoutMs}ms` }], }; } return { content: [{ type: "text", text: JSON.stringify(taskData, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } ); };
- src/tools/task-tools.ts:34-38 (schema)TypeScript interface defining the input parameters for the wait-for-task handler.interface WaitForTaskParams { taskUid: number; timeoutMs?: number; intervalMs?: number; }