Skip to main content

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. :::

InterfaceSource of truthNotes
RESTapis/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.
Eventsapis/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.
MCPADR 0008, internal/adapters/inbound/mcpcmd/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.
A2AADR 0011, internal/adapters/inbound/a2acmd/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.

TagEndpointOperation idSuccess
NodesPOST /nodesregisterNode201, the node in PROPOSED
NodesGET /nodeslistNodes200 {items, nextCursor}, by id, filters type, region, status
NodesGET /nodes/{nodeId}getNode200, the node with its current operationalProfile
NodesPUT /nodes/{nodeId}/operational-profiledeclareOperationalProfile200, the node with the new revision
NodesPOST /nodes/{nodeId}/activationsactivateNode200, the node ACTIVE
NodesPOST /nodes/{nodeId}/suspensionssuspendNode200, the node SUSPENDED (body {reason})
NodesPOST /nodes/{nodeId}/retirementsretireNode200, the node RETIRED
LanesPOST /lanesopenLane201, the lane OPEN
LanesGET /laneslistLanes200 {items, nextCursor}, filters origin, destination
LanesPOST /lanes/{laneId}/closurescloseLane200, the lane CLOSED
LanesPOST /lanes/{laneId}/cost-declarationsdeclareLaneCost201, the lane with the declared costPerUnitCents
Service areasPUT /service-areas/{postalPrefix}assignServiceArea200, the assignment at its new version
Service areasGET /service-areas/{postalPrefix}resolveServiceArea200, the current assignment; 404 not-found if unassigned
RegionsPOST /regionsdefineRegion201, the region
RegionsGET /regionslistRegions200 {items, nextCursor}, regions
RegionsGET /regions/{regionId}getRegion200, the region
HealthGET /healthz, GET /readyznone (not in the spec)200, or 503 on /readyz while draining or a dependency is down

Conventions in the contract​

  • Idempotency-Key. Required on every POST and on the two appending PUTs (PUT /nodes/{nodeId}/operational-profile, PUT /service-areas/{postalPrefix}); 400 idempotency-key-required when absent, 400 idempotency-key-invalid unless 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 header Idempotency-Replayed: true; with a different request it is 409 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 carries profileRevision and a service area assignmentVersion; the caller sends the next number and a stale one is 409 stale-profile-revision or 409 stale-assignment-version. Profile revisions are immutable and kept.
  • Lists. Keyset-paginated: nodes, lanes and regions come back by id ascending as {items, nextCursor} (limit 1-500, default 100, opaque cursor; nextCursor is absent on the last page), {items: []} when nothing matches. 400 invalid-limit, 400 invalid-cursor, and 400 unknown-query-parameter for any parameter the collection does not declare. An unknown type or status filter is 422 validation-failed. The MCP list_regions still wraps every region as {regions}.
  • Errors are RFC 9457 application/problem+json with type set to the slug alone (not a URL), plus title, status, detail and instance. 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-unavailable and internal-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 is 400.
  • Auth: none. The fleet reverted REST, MCP and A2A auth on 2026-09-11, and TestNoAuthMiddlewareReintroduced fails CI if auth middleware returns under internal/adapters/inbound.
  • Events are the Published Language: dispatch on the full type, ignore unknown types, deduplicate on the CloudEvents id, keep the highest profileRevision or assignmentVersion per 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 idArgumentsAnswers
serving_stationpostalPrefix (required, matched exactly)The assignment (deliveryStationNodeId, regionId, assignmentVersion) together with the station node and its current operational profile.
find_nodestype, 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.