wait
Introduces a timed pause into workflows by waiting for a specified number of seconds, ensuring asynchronous operations complete before proceeding to the next step.
Instructions
Waits for a specified duration in seconds.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| duration_seconds | Yes |
Implementation Reference
- src/index.ts:21-39 (handler)The handler function that executes the 'wait' tool logic: logs start, waits using setTimeout for the specified duration in seconds, logs finish, and returns success content. Handles errors similarly.async function waitHandler(args: z.infer<typeof waitInputSchema>): Promise<CallToolResult> { const { duration_seconds } = args; try { console.error(`[mcp-wait-timer] Waiting for ${duration_seconds} seconds...`); await new Promise(resolve => setTimeout(resolve, duration_seconds * 1000)); console.error(`[mcp-wait-timer] Wait finished.`); return { isError: false, content: [{ type: 'text', text: `Successfully waited for ${duration_seconds} seconds.` }], }; } catch (error: any) { console.error(`[mcp-wait-timer] Error during wait: ${error.message}`); // Ensure error responses also conform to CallToolResult return { isError: true, content: [{ type: 'text', text: `Error waiting: ${error.message}` }], }; } }
- src/index.ts:16-19 (schema)Zod schema definition for input validation of the 'wait' tool, defining duration_seconds as a positive number.const waitInputSchemaShape = { duration_seconds: z.coerce.number().positive().describe('The number of seconds to wait'), // Use coerce.number() }; const waitInputSchema = z.object(waitInputSchemaShape);
- src/index.ts:43-51 (registration)Tool registration object defining the 'wait' tool with name, description, and input schema shape.const WAIT_TOOL: Tool = { name: 'wait', description: 'Waits for a specified duration in seconds.', inputSchema: { type: 'object', properties: waitInputSchemaShape, required: ['duration_seconds'], }, };
- src/index.ts:63-65 (registration)Registers the 'wait' tool (WAIT_TOOL) in the MCP server's list tools response handler.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [WAIT_TOOL], }));
- src/index.ts:67-79 (registration)Registers the call tool handler that dispatches to waitHandler if tool name is 'wait', including input validation.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name === WAIT_TOOL.name) { const parseResult = waitInputSchema.safeParse(request.params.arguments); if (!parseResult.success) { throw new McpError( ErrorCode.InvalidParams, `Invalid arguments for tool ${WAIT_TOOL.name}: ${parseResult.error.message}` ); } return waitHandler(parseResult.data); } throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`); });