Expand description
Fluent builder for mocking an A2A (Agent-to-Agent) protocol server.
This is an idiomatic Rust port of the Java client A2aMockBuilder
(org.mockserver.client.A2aMockBuilder). It produces the same wire-level
expectation JSON: a set of HTTP expectations that emulate an A2A agent —
a discoverable agent card plus a JSON-RPC 2.0 task endpoint.
Each generated expectation either:
- serves the agent card on
GET <agentCardPath>(a static JSON response), or - matches a JSON-RPC method (
tasks/send,tasks/get,tasks/cancel,tasks/pushNotificationConfig/set, or the streaming method) onPOST <path>and responds with a Velocity template that echoes the incoming JSON-RPC id via$!{request.jsonRpcRawId}.
Optional capabilities mirror the Java builder exactly:
- streaming — advertises
capabilities.streaming: trueand adds an SSE expectation for the streaming method (defaultmessage/stream) that emits aworkingstatus-update, an artifact-update, then acompleted(final: true) status-update, each wrapped in a JSON-RPC 2.0 envelope. - push notifications — advertises
capabilities.pushNotifications: true, echoes the registered config fromtasks/pushNotificationConfig/set, and replaces the plaintasks/sendexpectation with an override-forwarded-request that POSTs the completed task to the configured webhook while still returning the JSON-RPC task response to the caller.
§Example
use mockserver_client::a2a::a2a_mock_default;
let expectations = a2a_mock_default()
.with_agent_name("TestAgent")
.with_skill("translate")
.with_name("Translation")
.with_description("Translates text")
.with_tag("i18n")
.and()
.on_task_send()
.matching_message("translate.*")
.responding_with("Bonjour", false)
.and()
.build();
// agent card + custom handler + tasks/send + tasks/get + tasks/cancel
assert_eq!(expectations.len(), 5);Structs§
- A2aMock
Builder - Fluent builder producing the expectations for a mocked A2A agent.
- A2aSkill
Builder - Sub-builder for a single A2A skill. Call
andto return to the parentA2aMockBuilder. - A2aTask
Handler Builder - Sub-builder for a single custom
tasks/sendhandler. Callandto return to the parentA2aMockBuilder.
Functions§
- a2a_
mock - Create a new A2A mock builder targeting
pathfor the JSON-RPC task endpoint. - a2a_
mock_ default - Create a new A2A mock builder targeting the default
/a2apath.