Skip to content

feat(a2a): HTTP+JSON/REST protocol binding beside JSON-RPC - #14

Open
brainsparker wants to merge 1 commit into
mainfrom
feature/2026-10-03-a2a-rest-binding
Open

brainsparker wants to merge 1 commit into
mainfrom
feature/2026-10-03-a2a-rest-binding

Conversation

@brainsparker

Copy link
Copy Markdown
Owner

What this does

A2AServer now serves the A2A v1.0 HTTP+JSON/REST protocol binding (spec section 11) beside the existing JSON-RPC endpoint. Same handlers, same in-memory task store, second transport. Any REST-speaking A2A client can now talk to a youagent agent without a JSON-RPC envelope.

Routes follow the v1.0 method mapping (spec section 5.3), with no /v1 prefix (1.0 removed it):

Operation Route Response
SendMessage POST /message:send 200, { "task": Task }
GetTask GET /tasks/{id}?historyLength=n 200, Task
ListTasks GET /tasks?contextId=&status=&pageSize=&pageToken=&historyLength= 200, { tasks, nextPageToken, pageSize, totalSize }
CancelTask POST /tasks/{id}:cancel 200, Task
CreateTaskPushNotificationConfig POST /tasks/{id}/pushNotificationConfigs 201, flattened config
ListTaskPushNotificationConfigs GET /tasks/{id}/pushNotificationConfigs 200, { configs, nextPageToken }
GetTaskPushNotificationConfig GET /tasks/{id}/pushNotificationConfigs/{configId} 200, flattened config
DeleteTaskPushNotificationConfig DELETE /tasks/{id}/pushNotificationConfigs/{configId} 204
SendStreamingMessage, SubscribeToTask POST /message:stream, POST /tasks/{id}:subscribe (GET accepted too) 400 UNSUPPORTED_OPERATION while streaming: false
GetExtendedAgentCard GET /extendedAgentCard 400 EXTENDED_AGENT_CARD_NOT_CONFIGURED

Errors are google.rpc.Status JSON per spec section 11.6, using the section 5.4 HTTP status table, and always carry a google.rpc.ErrorInfo detail (reason: TASK_NOT_FOUND, domain: a2a-protocol.org, and so on) so clients can tell apart errors that share a status code. Requests may be application/json or application/a2a+json; anything else is ContentTypeNotSupportedError. Responses are application/a2a+json.

The served card gains an HTTP+JSON entry in supportedInterfaces for each JSON-RPC entry (JSON-RPC stays first, so it remains the preferred interface). restBinding: false on A2AServerConfig turns the whole thing off, including the advertisement.

Try it:

curl -s -X POST http://localhost:3141/message:send \
  -H 'Content-Type: application/a2a+json' \
  -d '{"message":{"messageId":"m1","role":"user","parts":[{"kind":"text","text":"hello"}]}}'
curl -s http://localhost:3141/tasks
curl -s -i http://localhost:3141/tasks/missing   # 404, error.details[0].reason = TASK_NOT_FOUND

Why this, why today

youagent's A2A story so far has been JSON-RPC only. The v1.0 spec defines three bindings and the ecosystem has standardized on shipping all of them:

Runner-up candidates considered today and passed on:

  1. frugal: adopt the MCP 2026-07-28 spec changes (resultType, ttlMs/cacheScope, server/discover). Verified the spec changelog, but the Go SDK already implements all of it as of go-sdk v1.7.0 (frugal pins v1.6.1), so this is a dependency bump rather than a feature. Source: https://modelcontextprotocol.io/specification/2026-07-28/changelog and https://github.com/modelcontextprotocol/go-sdk/releases/tag/v1.8.0
  2. you-aware (MCP-Profiles): declare outputSchema and return structuredContent per the same MCP revision. Real and timely, but the repo has three unreviewed daily PRs already and no merge history for them, so a fourth would sit in the same queue.

The REST binding does not overlap any open youagent PR (#10 streaming, #11 auth, #12 signed cards, #13 serve from start). When #10 lands, the two streaming routes here can hand off to the SSE path; until then they answer the same UnsupportedOperationError the JSON-RPC binding does.

Implementation notes

  • New src/a2a/rest.ts: route table (REST_ROUTES, matchRestRoute), error mapping (restStatusFor, toRestErrorBody), card helper (withHttpJsonInterface), query coercion. All exported from youagent.
  • A2AServer: handleRequest falls through to handleRest for matched routes; restParams builds the params the existing handler expects from path, query and body; sendRestResult applies the REST response shapes (SendMessageResponse wrapper, 201 on create, 204 on delete). Handlers are invoked under the 1.0 PascalCase operation name so push config responses come back flattened, which is also what REST specifies. The path task id wins over any taskId in a create body.
  • A2A_ERROR_CODES gains -32007, -32008, -32009 from the 1.0 table.
  • Response shapes were checked against a2a-js src/server/express/rest_handler.ts and src/errors/rest.ts (status codes, REQUEST_MALFORMED reason for structural errors, 201/204 on config create/delete, both GET and POST on :subscribe).
  • One existing test updated: the card discovery test now expects both interfaces on the served card.
  • README: new "HTTP+JSON/REST binding" subsection with the route table, plus updated limitations (gRPC binding, REST client). CHANGELOG: Unreleased entry. Example header: REST curl lines.

Test status

  • npm run typecheck: clean
  • npm test: 15 files, 166 tests passing (16 new REST tests in src/a2a/a2a-server.rest.test.ts covering the route table, the error mapping, the card helper, every route including pagination and error paths, content-type handling, the shared task store, and restBinding: false)
  • npm run build: tsup ESM + DTS build succeeds
  • Live smoke test against the built package with curl: card advertises both bindings; message:send 200 as application/a2a+json; task get and list 200; unknown task 404 with TASK_NOT_FOUND ErrorInfo; push config create 201; message:stream 400 UNSUPPORTED_OPERATION; /v1/tasks 404
  • Not run: a2a-tck against this server (needs Python 3.11 and a REST-declared card, which this PR provides; a follow-up could add an a2a:tck script)

🤖 Generated with Claude Code

Serve the A2A v1.0 REST binding (spec section 11) over the same handlers
and task store as the JSON-RPC endpoint: message:send, tasks get/list/
cancel, push notification config sub-resource, extendedAgentCard, with
google.rpc.Status error bodies and the section 5.4 status mapping. The
served card advertises an HTTP+JSON interface next to each JSON-RPC one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant