PROMPT 03 Ready State Requests
# Implementation Prompt 03: Ready State - Request/Response Path **Goal:** Implement :ready state request handling, response routing, request timeouts, and basic notifications. > **Update (2025-11-07):** Replace any per-request `:state_timeout` actions with `:erlang.send_after/3` messages (`{:req_timeout, id}`), and keep calls synchronous (store `from`; do **not** reply `{:ok, id}` immediately). Treat the remainder of this prompt as historical context where it conflicts with ADR-0003/ADR-0007. **Test Strategy:** TDD with rgr. All tests green, no warnings. --- ## Context: What You're Building You're implementing the core request/response cycle in the :ready state: 1. Client calls arrive (call_tool, list_resources, etc.) 2. Generate request ID, build JSON-RPC frame 3. Send frame to transport 4. Track request with timeout 5. Route response back to caller 6. Handle request timeouts This prompt covers the **happy path** and basic timeout handling. Retry logic and failure paths come in Prompt 04. --- ## Required Reading: State Transitions From STATE_TRANSITIONS.md, these are the exact transitions to implement: ### :ready State - Request/Response | From | Event | Guard | Actions | To | |------|-------|-------|---------|-----| | :ready | `{:call, from}, {:request, method, params, opts}` | - | Generate ID; build JSON-RPC frame; send frame; if `:ok` → track request with timeout; reply `{:ok, id}` or `{:error, reason}` | :ready | | :ready | `{:info, {:transport, :frame, binary}}` | response with known ID | Decode; cancel timeout; reply to caller; tombstone ID; set_active(:once) | :ready | | :ready | `{:info, {:transport, :frame, binary}}` | response with unknown ID | Log debug (tombstoned/late); set_active(:once) | :ready | | :ready | `{:info, {:transport, :frame, binary}}` | notification | Decode; invoke handlers (sync); set_active(:once) | :ready | | :ready | `{:state_timeout, {:request_timeout, id}}` | ID exists | Reply error; tombstone ID | :ready | | :ready | `{:state_timeout, {:request_timeout, id}}` | ID tombstoned | Ignore (already replied) | :ready | ### Request Struct (from ADR-0003)
fill the variables
This prompt has 7 variables. Pro fills them into a ready-to-paste prompt for you — no manual find-and-replace.
{:req_timeout, id}{:ok, id}{:call, from}{:request, method, params, opts}{:error, reason}{:info, {:transport, :frame, binary}{:state_timeout, {:request_timeout, id}
Unlock with Pro →when to use it
Community prompt sourced from the open-source GitHub repo nshkrdotcom/mcp_client (MIT). A "PROMPT 03 Ready State Requests" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
roleplaycommunitygeneral
source
nshkrdotcom/mcp_client · MIT