Skip to main content

Module a2a

Module a2a 

Source
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) on POST <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: true and adds an SSE expectation for the streaming method (default message/stream) that emits a working status-update, an artifact-update, then a completed (final: true) status-update, each wrapped in a JSON-RPC 2.0 envelope.
  • push notifications — advertises capabilities.pushNotifications: true, echoes the registered config from tasks/pushNotificationConfig/set, and replaces the plain tasks/send expectation 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§

A2aMockBuilder
Fluent builder producing the expectations for a mocked A2A agent.
A2aSkillBuilder
Sub-builder for a single A2A skill. Call and to return to the parent A2aMockBuilder.
A2aTaskHandlerBuilder
Sub-builder for a single custom tasks/send handler. Call and to return to the parent A2aMockBuilder.

Functions§

a2a_mock
Create a new A2A mock builder targeting path for the JSON-RPC task endpoint.
a2a_mock_default
Create a new A2A mock builder targeting the default /a2a path.