API overview
:::info Implemented by cmd/api, cmd/mcp and cmd/a2a
cmd/api serves every REST route below (internal/adapters/inbound/http) on HTTP_ADDR (default :8080). The contracts are apis/openapi.yaml and apis/asyncapi.yaml, pinned by ADR 0001, ADR 0002 and ADR 0006. The router registers the 15 operations of the spec plus /healthz and /readyz, which the spec does not list. See the Quickstart for real responses.
:::
| Interface | Source of truth | Notes |
|---|---|---|
| REST | apis/openapi.yaml (OpenAPI 3.0.3, version 0.1.0) | The pages under REST are generated from the spec with npm run gen-api-docs; do not edit them by hand. The only server the spec names is http://localhost:8080; through Kong in the fleet the api is at /api/node-topology with the prefix stripped. |
| Events | apis/asyncapi.yaml (AsyncAPI 3.0.0, version 1.0.0) | Ten CloudEvents on retailnetwork.node-topology.events; summarised on the event catalogue, every field on Domain events. |
| MCP | ADR 0008, internal/adapters/inbound/mcp | cmd/mcp serves Streamable HTTP on /mcp and / (port 8090; through Kong /api/mcp/node-topology). Six read-only tools, no write tool; see MCP tools. |
| A2A | ADR 0011, internal/adapters/inbound/a2a | cmd/a2a serves JSON-RPC 2.0 on / and /a2a (port 8093; through Kong /api/a2a/node-topology). Two read-only skills; see below. |
Endpoints
All routes are on cmd/api. State-changing routes need an Idempotency-Key.
| Tag | Endpoint | Operation id | Success |
|---|---|---|---|
| Nodes | POST /nodes | registerNode | 201, the node in PROPOSED |
| Nodes | GET /nodes | listNodes | 200 {items, nextCursor}, by id, filters type, region, status |
| Nodes | GET /nodes/{nodeId} | getNode | 200, the node with its current operationalProfile |
| Nodes | PUT /nodes/{nodeId}/operational-profile | declareOperationalProfile | 200, the node with the new revision |
| Nodes | POST /nodes/{nodeId}/activations | activateNode | 200, the node ACTIVE |
| Nodes | POST /nodes/{nodeId}/suspensions | suspendNode | 200, the node SUSPENDED (body {reason}) |
| Nodes | POST /nodes/{nodeId}/retirements | retireNode | 200, the node RETIRED |
| Lanes | POST /lanes | openLane | 201, the lane OPEN |
| Lanes | GET /lanes | listLanes | 200 {items, nextCursor}, filters origin, destination |
| Lanes | POST /lanes/{laneId}/closures | closeLane | 200, the lane CLOSED |
| Lanes | POST /lanes/{laneId}/cost-declarations | declareLaneCost | 201, the lane with the declared costPerUnitCents |
| Service areas | PUT /service-areas/{postalPrefix} | assignServiceArea | 200, the assignment at its new version |
| Service areas | GET /service-areas/{postalPrefix} | resolveServiceArea | 200, the current assignment; 404 not-found if unassigned |
| Regions | POST /regions | defineRegion | 201, the region |
| Regions | GET /regions | listRegions | 200 {items, nextCursor}, regions |
| Regions | GET /regions/{regionId} | getRegion | 200, the region |
| Health | GET /healthz, GET /readyz | none (not in the spec) | 200, or 503 on /readyz while draining or a dependency is down |
Conventions in the contract
Idempotency-Key. Required on everyPOSTand on the two appendingPUTs (PUT /nodes/{nodeId}/operational-profile,PUT /service-areas/{postalPrefix});400 idempotency-key-requiredwhen absent,400 idempotency-key-invalidunless 1 to 128 printable ASCII characters. The key is global: the same key with an equal method, path and body replays the stored answer byte for byte with headerIdempotency-Replayed: true; with a different request it is409 idempotency-key-reused. Keys live 24 hours. A 2xx and a refusal that is a function of the request alone are stored; a 5xx never, and neither is a refusal that depends on state another request can change (not-found,illegal-transition,concurrent-update,incomplete-operational-profile,serving-station-not-allowed,lane-endpoint-not-active,duplicate-lane,not-a-delivery-station,handoff-node-not-usable,unknown-region): the key is released and a retry under it runs again (ADR 0020).- Versioning without ETags. There is no
If-Match. A profile carriesprofileRevisionand a service areaassignmentVersion; the caller sends the next number and a stale one is409 stale-profile-revisionor409 stale-assignment-version. Profile revisions are immutable and kept. - Lists. Keyset-paginated: nodes, lanes and regions come back by id ascending as
{items, nextCursor}(limit1-500, default 100, opaquecursor;nextCursoris absent on the last page),{items: []}when nothing matches.400 invalid-limit,400 invalid-cursor, and400 unknown-query-parameterfor any parameter the collection does not declare. An unknowntypeorstatusfilter is422 validation-failed. The MCPlist_regionsstill wraps every region as{regions}. - Errors are RFC 9457
application/problem+jsonwithtypeset to the slug alone (not a URL), plustitle,status,detailandinstance. The slugs:not-found,method-not-allowed,illegal-transition,concurrent-update,validation-failed,malformed-request-body,malformed-request-query,request-body-too-large,idempotency-key-required,idempotency-key-invalid,idempotency-key-reused,vendor-node-code-taken,operator-not-allowed-for-node-type,subtype-not-allowed,stale-profile-revision,incomplete-operational-profile,cutoff-outside-operating-hours,sort-dwell-not-allowed,inbound-limits-not-allowed,node-retired,lane-loop,lane-type-pair-not-allowed,lane-endpoint-not-active,duplicate-lane,not-a-delivery-station,stale-assignment-version,region-code-taken,unknown-region,dependency-unavailableandinternal-error. Status, trigger and remedy for each are on Troubleshooting; the use case that raises each is on Use cases. - Limits. Request bodies over 64 KiB are
413 request-body-too-large; a NUL character in a body or query string is400. - Auth: none. The fleet reverted REST, MCP and A2A auth on 2026-09-11, and
TestNoAuthMiddlewareReintroducedfails CI if auth middleware returns underinternal/adapters/inbound. - Events are the Published Language: dispatch on the full
type, ignore unknown types, deduplicate on the CloudEventsid, keep the highestprofileRevisionorassignmentVersionper aggregate.
MCP
cmd/mcp serves the six read tools get_node, list_nodes, list_lanes, resolve_service_area, get_region and list_regions over Streamable HTTP. Each is annotated read-only, idempotent and closed-world; a test fails the build on a write-verb name. Errors come back as an isError tool result with text <slug>: <detail>. The input fields of every tool are on MCP tools.
A2A
cmd/a2a is a message-only agent: each request is one JSON-RPC message whose first part (a data part, or a text part holding the same JSON) is {"skill": "<id>", "arguments": {...}}; the reply is one agent message holding a data part and a one-line text summary. Unknown fields are rejected. The Agent Card is served at /.well-known/agent-card.json (name node-topology, JSON-RPC transport, no streaming, no security schemes) and advertises the URL set in A2A_AGENT_URL.
| Skill id | Arguments | Answers |
|---|---|---|
serving_station | postalPrefix (required, matched exactly) | The assignment (deliveryStationNodeId, regionId, assignmentVersion) together with the station node and its current operational profile. |
find_nodes | type, regionId, status, all optional and combined with AND | {count, nodes} by id ascending. |
{"skill":"find_nodes","arguments":{"type":"DELIVERY_STATION","status":"ACTIVE"}}
Domain rejections are answered inside the message envelope as a problem object, never as a JSON-RPC error: not-found (404) for an unassigned prefix, validation-failed (422) for a bad type or status, invalid-argument (400) for a missing postalPrefix, unknown argument or NUL character, malformed-skill-request (400) for a message that is not a skill request, unknown-skill (400), and internal-error (500). The A2A routes are not in apis/openapi.yaml; /a2a and / are described only here and in ADR 0011.