PROMPT 02 Starting And Initializing
# Implementation Prompt 02: Starting and Initializing States **Goal:** Implement :starting and :initializing state logic with transport spawn, initialize handshake, and capability validation. **Test Strategy:** TDD with rgr. All tests green, no warnings. --- ## Context: What You're Building You're implementing the first two states of the Connection state machine: - **:starting**: Spawn the transport process - **:initializing**: Send initialize request, validate server capabilities, transition to :ready The scaffold from Prompt 01 is already in place. Now you're adding the actual state logic. --- ## Required Reading: State Transitions From STATE_TRANSITIONS.md, these are the exact transitions to implement: ### :starting State | From | Event | Guard | Actions | To | |------|-------|-------|---------|-----| | :starting | `{:internal, {:spawn_transport, opts}}` | - | Spawn transport child; wait for `transport_up` | :initializing | | :starting | `{:call, from}, :stop` | - | Reply `{:ok, :ok}`; exit(normal) | - | ### :initializing State | From | Event | Guard | Actions | To | |------|-------|-------|---------|-----| | :initializing | `{:info, {:transport, :up}}` | - | **Send `initialize` request then set_active(:once)**; arm init_timeout | :initializing | | :initializing | `{:info, {:transport, :frame, binary}}` | `byte_size > max` | Log error; close transport (no set_active); schedule backoff | :backoff | | :initializing | `{:info, {:transport, :frame, binary}}` | decode error | Log warning; set_active(:once) (stay in init) | :initializing | | :initializing | `{:info, {:transport, :frame, binary}}` | valid init response, **caps valid** | Store caps; bump session_id; reset backoff_delay; reply "initialized"; arm tombstone sweep; set_active(:once) | :ready | | :initializing | `{:info, {:transport, :frame, binary}}` | valid init response, **caps invalid** | Log error; close transport (no set_active); schedule backoff | :backoff | | :initializing | `{:state_timeout, :init_timeout}` | - | Close transport (no set_active); schedule backoff | :backoff | | :initializing | `{:info, {:transport, :down, reason}}` | - | Log error; schedule backoff | :backoff | | :initializing | `{:call, from}, :stop` | - | Reply `{:ok, :ok}`; close transport; exit(normal) | - | --- ## Key Requirements from ADRs ### ADR-0002: Transport Message Contract Transport MUST emit exactly:
fill the variables
This prompt has 7 variables. Pro fills them into a ready-to-paste prompt for you — no manual find-and-replace.
{:internal, {:spawn_transport, opts}{:call, from}{:ok, :ok}{:info, {:transport, :up}{:info, {:transport, :frame, binary}{:state_timeout, :init_timeout}{:info, {:transport, :down, reason}
Unlock with Pro →when to use it
Community prompt sourced from the open-source GitHub repo nshkrdotcom/mcp_client (MIT). A "PROMPT 02 Starting And Initializing" 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
businesscommunitygeneral
source
nshkrdotcom/mcp_client · MIT