Skip to main content
Glama
devlimelabs

Meilisearch MCP Server

by devlimelabs

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
NameRequiredDescriptionDefault
taskUidYesUnique identifier of the task to wait for
timeoutMsNoMaximum time to wait in milliseconds (default: 5000)
intervalMsNoPolling interval in milliseconds (default: 500)

Implementation Reference

  • 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);
        }
      }
    );
  • 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)"),
    },
  • 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);
          }
        }
      );
    };
  • TypeScript interface defining the input parameters for the wait-for-task handler.
    interface WaitForTaskParams {
      taskUid: number;
      timeoutMs?: number;
      intervalMs?: number;
    }

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/devlimelabs/meilisearch-ts-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server