sleep
Pause operations for a specified duration in milliseconds. Use this tool to add delays between tasks, such as waiting between API calls or testing eventually consistent systems.
Instructions
Wait for a specified duration
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| milliseconds | Yes | Duration to wait in milliseconds |
Implementation Reference
- src/services/sleep.ts:10-16 (handler)Core handler logic for the sleep tool: validates input milliseconds and performs the sleep using setTimeout.async sleep(ms: number): Promise<void> { if (isNaN(ms) || ms < 0) { throw new Error("milliseconds must be a non-negative number"); } return new Promise(resolve => setTimeout(resolve, ms)); }
- src/index.ts:56-77 (handler)MCP server handler for CallToolRequestSchema, specifically handles the 'sleep' tool by extracting milliseconds, calling the service, and returning success content.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== "sleep") { throw new McpError(ErrorCode.MethodNotFound, "Unknown tool"); } try { const ms = Number(request.params.arguments?.milliseconds); await service.sleep(ms); return { content: [{ type: "text", text: `Waited for ${ms} milliseconds` }] }; } catch (error) { throw new McpError( ErrorCode.InvalidParams, error instanceof Error ? error.message : "Unknown error" ); } });
- src/index.ts:33-49 (schema)Input schema definition for the sleep tool: requires 'milliseconds' as a non-negative number.{ name: "sleep", description: "Wait for a specified duration", inputSchema: { type: "object", properties: { milliseconds: { type: "number", description: "Duration to wait in milliseconds", minimum: 0 } }, required: ["milliseconds"] } } ] };
- src/index.ts:30-50 (registration)Registration of the sleep tool via the ListToolsRequestSchema handler, which returns the tool metadata including schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "sleep", description: "Wait for a specified duration", inputSchema: { type: "object", properties: { milliseconds: { type: "number", description: "Duration to wait in milliseconds", minimum: 0 } }, required: ["milliseconds"] } } ] }; });
- src/services/sleep.ts:4-16 (helper)SleepService class providing the sleep functionality as a helper for the main handler.export class SleepService { /** * Wait for the specified duration * @param ms Duration to wait in milliseconds * @returns Promise that resolves after the duration */ async sleep(ms: number): Promise<void> { if (isNaN(ms) || ms < 0) { throw new Error("milliseconds must be a non-negative number"); } return new Promise(resolve => setTimeout(resolve, ms)); }