Appearance
0031. Swagger UI and the A2A REST binding ​
Status: Accepted (2026-10-07), decided by the owner on 2026-10-07 (the four decisions below); the owner may revisit. Builds on ADR 0030 (the methods both bindings serve).
Context ​
Every adam agent spoke A2A 1.0 over JSON-RPC only (POST /), and nothing described the API to a person: trying a call meant writing a JSON-RPC envelope with curl. A2A 1.0 defines three bindings, and the SDK the server is built on already ships the HTTP+JSON one (a2a-server-lf 0.4.4, src/rest.rs).
Facts the design rests on, each verified 2026-10-07 unless it says otherwise:
- The REST binding (A2A 1.0 §11, https://a2a-protocol.org/latest/specification/):
POST /message:send,POST /message:stream(SSE),GET /tasks/{id},GET /tasks,POST /tasks/{id}:cancel,POST /tasks/{id}:subscribe(SSE),/tasks/{id}/pushNotificationConfigs[/{configId}](POST,GET,DELETE),GET /extendedAgentCard; errors are agoogle.rpc.Statuswhosedetailscarry anErrorInfowith the A2A reason (§11.6);application/a2a+jsonSHOULD be the content type (§11.1). - Where it is: an
AgentInterface'surlis "the URL or address where this interface is available" (§4.4.6); the REST paths are relative to it (§11.3, and the SDK's client appends them to the interface URL:a2a-client-lf0.2.5src/rest.rs).supportedInterfacesis an "Ordered list of supported interfaces. The first entry is preferred." (§4.4.1, §8.3.1). - The SDK's
rest_router(a2a-server-lf0.4.4src/rest.rs, read whole): it is generic over the sameRequestHandlertrait asjsonrpc_router, passes every request header to the handler asServiceParams, limits bodies to the same 10 MiB, maps anA2AErrorto the HTTP status and envelope of §11.6, and also answers the paths of earlier drafts (/message/send,/tasks/{id}/cancel,/tasks/{id}/push-configs,/agent-card/extended,GET /tasks/{id}:subscribe, ...). What it does not do: itsJsonandQueryextractors refuse a malformed request with plain text (400, 413, 415, 422), its error builder is private, and, like the JSON-RPC route, it reads a send as proto3 JSON and dropsconfiguration.pushNotificationConfig(the name of an earlier draft) silently. - The assets:
utoipa-swagger-ui10.0.1 with thevendoredfeature takes Swagger UI 5.32.6 from the zip in theutoipa-swagger-ui-vendored0.2.0 crate (itsbuild.rsreadsutoipa_swagger_ui_vendored::SWAGGER_UI_VENDOREDwhenCARGO_FEATURE_VENDOREDis set, and downloads only otherwise; the zip is in the crate'sres/): nothing is fetched at build time. Both crates are MIT OR Apache-2.0 and need Rust 1.88 (the workspace's MSRV is 1.94). - Swagger UI resolves a relative server URL against the URL it read the document from (
oas3BaseUrlandbuildOas3UrlWithContextin the bundledswagger-ui-bundle.js, with the spec URL made absolute against the page byurl-parse), and cannot show a stream as it arrives: it waits for the whole response. Verified 2026-10-07 in headless Chromium (Playwright) againstadam-agenton PostgreSQL 16: the page renders under the policy below with no console error, no CSP violation and no request to another origin; Authorize then Try it out onPOST /message:sendand onPOST /(an example from the dropdown) reach the server with the bearer token.
Decision ​
- Both bindings, one handler. The SDK's
rest_routeris mounted besidejsonrpc_routerover the sameBackendHandler, so caller identity, extension activation, push configs,ListTasks, the extended card and the mapping of aBackendErrorare one code path (crates/adam-a2a/src/server.rs). It is wrapped, not reimplemented: the sameecho_extensionslayer (readingmessage.extensionsof a REST send), andrest::rejections, which answers the extractors' plain-text refusals and a send that namespushNotificationConfigin the binding's own envelope (crates/adam-a2a/src/rest.rs; the envelope is rebuilt there because the SDK's builder is private). A 401 on a REST path is agoogle.rpc.StatusUNAUTHENTICATED; atPOST /it stays the JSON-RPC error-32000. The SDK's aliases of earlier drafts stay mounted, and are documented as deprecated. - The card lists
JSONRPCfirst andHTTP+JSONsecond, at the same URL (PUBLIC_URL): a client that takes the first interface, like the orchestration layer, is unchanged. - One OpenAPI 3.1 document of both, at
GET /openapi.json, with Swagger UI atGET /docs. JSON-RPC isPOST /with a request body that is aoneOfof one schema per method and a named example per method (a dropdown in Swagger UI). The streaming methods are documented astext/event-stream, and their descriptions say Swagger UI cannot show a stream and give thecurl. The document is written by hand from the SDK's types (crates/adam-a2a/src/openapi.rs):a2a-lfderives neitherutoipa::ToSchemanorschemars::JsonSchema, and the tests hold it to the code instead. - The page is public; the calls need the token.
/docs, the files the page loads and/openapi.jsonjoin the public routes (Authenticator::with_public_docs, as the key set joins them when the card is signed); nothing else does. The document declares the bearer scheme exactly when the server requires one, so Authorize sendsAuthorization: Bearer …. It is built once from the public card and the switches the card already shows, so it is the same for every caller and names no token and nothing of the extended card. - On by default, for every adam agent. It lives in
adam-a2a(ServerOptions::docs,with_docs) andadam-servicereadsA2A_DOCS(falseturns it off), soadam-coderandadam-agenthave it with no code of their own. - Assets in the binary.
utoipa-swagger-uiwithvendored(andminified: no source maps), itsservefunction and our own routes: only the eight filesindex.htmlloads are served, underContent-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; …(inlinestyleattributes are Swagger UI's React components;data:images are its stylesheet's icons). Its configuration points at../openapi.json, so the page works under a nested prefix, turns the validator badge (a call tovalidator.swagger.io) and?url=off, and does not persist the token. - Tested, not trusted (
crates/adam-a2a/tests/docs.rs,tests/rest.rs): the document validates against the official OpenAPI 3.1 JSON Schema (vendored intests/fixtures) and every$refresolves; every JSON-RPC method the handler dispatches is in theoneOfand the reverse, and each example reaches its method; every REST route is documented and every documented one is routed, and no other method is served on those paths; the examples, and real responses, stream events and errors from both bindings, validate against the document's schemas; the official client round-trips over HTTP+JSON. axum cannot list a router's routes, so the tables are pinned toa2a-server-lf0.4.4 by a test that fails whenCargo.lockmoves it. - The netcup deployment stays cluster-internal. No Ingress and no chart route: the docs are reached with
kubectl port-forward(deploy/coder/README.md).
The interaction is the sequence in Architecture. There is no lifecycle to draw: the document and the assets are built once when the router is, and never change while it runs.
Consequences ​
- The agent card has a second
supportedInterfacesentry; a client that prefersHTTP+JSONnow gets it. - New public routes:
GET /docs,/docs/and its files,GET /openapi.json(unlessA2A_DOCS=false). The REST paths are behind the token like every other route. ServerOptionsgainsdocs(Defaultis now hand-written: on);adam_service::A2aSettingsgainsdocs, so a literal built by hand needs it.- New dependencies:
utoipa-swagger-uiand, through it,utoipa,utoipa-gen,utoipa-swagger-ui-vendored,zip,mime_guess,flate2and their own (MIT, Apache-2.0, Zlib);jsonschema(already in the tree) for the tests. The binaries carry Swagger UI'sdist(about 4 MB, the unused ES bundles included: the crate embeds the whole folder). - Not done: no Ingress or public route to the docs; the streaming calls cannot be tried in Swagger UI (use the
curlthe page gives); the multi-tenant path prefix of A2A 1.0 (/{tenant}/…) is not served (neither binding has tenants here); responses areapplication/json, notapplication/a2a+json(the SDK's choice).
Alternatives rejected ​
- A REST layer of our own over
TaskBackend: a second path where the SDK already has one; it would drift from JSON-RPC. - Generating the document with
utoipaderives: the SDK's types derive nothing, and wrapper types would document a copy, not the wire. - Assets from a CDN, or downloaded by
build.rs: a page that depends on a third party, and an image build that needs GitHub. - The docs behind the token: Swagger UI cannot send a token before it has loaded the page and the document.