Skip to main content
Glama
Garoth

Sleep MCP Server

by Garoth

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
NameRequiredDescriptionDefault
millisecondsYesDuration to wait in milliseconds

Implementation Reference

  • 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));
    }
  • 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"
        );
      }
    });
  • 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"]
            }
          }
        ]
      };
    });
  • 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));
      }
Install Server

Other Tools

Related Tools

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/Garoth/sleep-mcp'

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