echo_with_delay
Simulate delayed responses in MCP protocol testing by echoing messages after a specified wait time up to 5 seconds.
Instructions
Echo back a message after a simulated delay.
Args: message: The message to echo back delay_seconds: Delay duration in seconds (max 5.0 seconds) ctx: MCP context
Returns: Echo response with timing information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | ||
| delay_seconds | No |
Implementation Reference
- src/mcp_echo/server.py:87-117 (handler)The handler function for the 'echo_with_delay' tool, which performs a sleep and returns timing data.
async def echo_with_delay( message: str, delay_seconds: float = 1.0, ctx: Context | None = None ) -> EchoDelayResponse: """Echo back a message after a simulated delay. Args: message: The message to echo back delay_seconds: Delay duration in seconds (max 5.0 seconds) ctx: MCP context Returns: Echo response with timing information """ # Limit delay to maximum of 5 seconds for safety delay_seconds = min(float(delay_seconds), 5.0) if ctx: await ctx.info(f"Echoing with {delay_seconds}s delay: {message[:50]}...") start_time = datetime.now(UTC) time.sleep(delay_seconds) end_time = datetime.now(UTC) return EchoDelayResponse( original_message=message, echoed_message=message, requested_delay=delay_seconds, actual_delay=(end_time - start_time).total_seconds(), start_time=start_time.isoformat(), end_time=end_time.isoformat(), timestamp=end_time.isoformat(), - src/mcp_echo/server.py:86-86 (registration)Registration of 'echo_with_delay' tool using the @mcp.tool() decorator.
@mcp.tool() - src/mcp_echo/api_models.py:19-28 (schema)Pydantic model defining the response schema for the 'echo_with_delay' tool.
"""Response model for echo_with_delay tool.""" original_message: str = Field(..., description="The original message sent") echoed_message: str = Field(..., description="The echoed message") requested_delay: float = Field(..., description="Requested delay in seconds") actual_delay: float = Field(..., description="Actual delay experienced in seconds") start_time: str = Field(..., description="ISO 8601 timestamp when delay started") end_time: str = Field(..., description="ISO 8601 timestamp when delay ended") timestamp: str = Field(..., description="ISO 8601 timestamp of the operation")