Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A2aproject A2a java JSONRPCTransport

From Leeroopedia
Knowledge Sources
Domains Client, JSON_RPC, Transport
Last Updated 2026-10-30 00:00 GMT

Overview

Concrete JSON-RPC 2.0 client transport implementation for A2A communication over HTTP, the default and most widely used transport protocol.

Description

The JSONRPCTransport class implements the ClientTransport SPI using the JSON-RPC 2.0 protocol over HTTP. It uses A2AHttpClient for HTTP communication, builds JSON-RPC request envelopes with method names from A2AMethods constants, and handles SSE streaming for `sendMessageStreaming` and `subscribeToTask` via SSEEventListener. JSON-RPC errors are mapped to A2A exceptions. The transport resolves the agent's preferred interface URL from the AgentCard.

Usage

  • Default A2A transport: The primary transport for A2A communication — most agents expose JSON-RPC endpoints
  • SSE streaming: Uses Server-Sent Events for streaming task updates and message streaming
  • Simple setup: Can be constructed with just an agent URL string for lightweight usage

Code Reference

Source Location

  • Repository: a2a-java
  • File: `client/transport/jsonrpc/src/main/java/org/a2aproject/sdk/client/transport/jsonrpc/JSONRPCTransport.java`
  • Lines: L71-381

Signature

public class JSONRPCTransport implements ClientTransport {
    public JSONRPCTransport(String agentUrl);
    public JSONRPCTransport(AgentCard agentCard);
    public JSONRPCTransport(@Nullable A2AHttpClient httpClient, @Nullable AgentCard agentCard,
                            AgentInterface agentInterface,
                            @Nullable List<ClientCallInterceptor> interceptors);

    // All ClientTransport methods: sendMessage, sendMessageStreaming,
    // getTask, cancelTask, listTasks, subscribeToTask,
    // createTaskPushNotificationConfiguration, etc.
}

Import

import org.a2aproject.sdk.client.transport.jsonrpc.JSONRPCTransport;

I/O Contract

Inputs

Name Type Required Description
agentUrl String Yes (simple ctor) Agent JSON-RPC endpoint URL
agentCard AgentCard Yes (card ctor) Resolved agent card
httpClient A2AHttpClient No Custom HTTP client (default created if null)
agentInterface AgentInterface Yes Interface with transport URL
interceptors List<ClientCallInterceptor> No Call interceptors for auth
request MessageSendParams Yes (sendMessage) Message parameters

Outputs

Name Type Description
sendMessage returns EventKind Message or Task response
Streaming events StreamingEventKind Delivered via SSE event consumer
getTask returns Task Task state
Exceptions A2AClientException Communication or protocol errors

Usage Examples

Simple JSON-RPC Message

import org.a2aproject.sdk.client.transport.jsonrpc.JSONRPCTransport;
import org.a2aproject.sdk.spec.EventKind;

// Create transport with just the agent URL
JSONRPCTransport transport = new JSONRPCTransport("http://localhost:9999");

EventKind result = transport.sendMessage(
    A2A.toMessageSendParams("Hello, agent!"), null);

With Agent Card and Streaming

JSONRPCTransport transport = new JSONRPCTransport(agentCard);

transport.sendMessageStreaming(
    A2A.toMessageSendParams("Generate a report"),
    event -> System.out.println("Update: " + event),
    error -> System.err.println("Stream error: " + error),
    null
);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment