ADR 0023: Build an upstream MCP client only when its endpoint is set
Status
Accepted (2026-10-13). Amends ADR 0007, whose step 4 constructed the order-management, labor-performance and process-path-management clients unconditionally. The optional-client rule of ADRs 0013, 0019, 0020 and 0021 is unchanged; this record extends it to every upstream.
Context
The composition root (cmd/agent/main.go) treated its twelve upstream MCP
clients two ways. Four of them (warehouse-planning, product-master,
inbound-receiving, network-inventory-planning) were built only when their
endpoint was set, so a nil port meant "not configured". The other eight
(wes-work-planning, fulfillment-execution, workforce-management,
facility-layout, inventory-storage, labor-performance, order-management,
process-path-management) were built even when the endpoint was empty.
Every call then dialled "" and failed with
unsupported protocol scheme "" at request time.
The fleet's ecosystem-gaps review recorded this as a trap: an unset
endpoint looked like an upstream outage in logs and traces, it cost an MCP
session attempt on every request, and detect_stranded_reservation had no
nil guard, so the only thing protecting it was that the client was never
nil.
Decision
newMCPClientincmd/agent/main.gobuilds an upstream's MCP client only when its endpoint is non-empty. Otherwise it returns the zero value of the port interface: a genuinely nil interface, never a non-nil interface around a nil pointer. All twelve clients go through it.- Every use case treats a nil port as an unavailable upstream, exactly
like a failed call:
- the daily brief marks the signal
unavailable(already nil-safe); - the flow balance returns a partial decision (already nil-safe);
DetectStrandedReservationskips the missing reads and degrades to an undetectedhold(new nil guards);- explain-travel-factor is not wired without facility-layout, so
GET /explain-travel-factoranswers503("explain travel factor not configured") and theexplain_travel_factortool is not registered. This is the same answer every other upstream-specific feature already gives when its upstream is not configured. Before this record it was a502from a failed dial.
- the daily brief marks the signal
- The startup log line reports
*_endpoint_configuredfor all twelve upstreams, so an operator sees which ones are off.
Consequences
- No request ever dials an empty URL. An unset endpoint is visible at startup instead of as a per-request transport error.
GET /explain-travel-factorwithout facility-layout changes from502to503. A502now always means facility-layout was configured and failed.- Tests:
TestNewOutboundClients_EmptyEndpointBuildsNoMCPClient,TestNewOutboundClients_SetEndpointBuildsEveryMCPClient,TestNewDecisionSupport_NoUpstreamsConfigured_DegradesWithoutPanicking,TestNewDecisionSupport_ExplainTravelFactorOnlyWiredWhenFacilityConfigured(cmd/agent/main_test.go) andTestDetectStrandedReservation_UnconfiguredUpstreams_DegradeToHold(internal/application/usecases).