Implementation:A2aproject A2a java A2ACardResolver
| Knowledge Sources | |
|---|---|
| Domains | Client, Service_Discovery |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete utility for fetching A2A AgentCards from remote agent endpoints, supporting tenant-specific paths, custom card locations, and authentication headers.
Description
`A2ACardResolver` fetches the `AgentCard` JSON manifest from an A2A agent's well-known endpoint (`/.well-known/agent-card.json`). It handles URL resolution with tenant support (`/.well-known/{tenant}/agent-card.json`), custom card paths, and authentication header injection.
The resolver uses a pluggable HTTP client (`A2AHttpClient`) with a default implementation created via `A2AHttpClientFactory.create()`. The fetched JSON is parsed through the gRPC protobuf `AgentCard.Builder` and converted to the SDK's `AgentCard` record via `ProtoUtils.FromProto.agentCard()`.
A fallback mechanism retries against the original base URL when the primary card URL returns 404, supporting agents that host the card at the base URL itself rather than the well-known path.
Usage
- Standard discovery: `A2ACardResolver.builder().baseUrl(url).build().getAgentCard()` — fetches from well-known endpoint
- Tenant-specific: Add `.tenant("my-tenant")` to fetch from tenant-specific path
- Authenticated: Add `.authHeader("Authorization", "Bearer token")` for protected endpoints
- Convenience method: `A2A.getAgentCard(url)` wraps this resolver for simple cases
Code Reference
Source Location
- Repository: a2a-java
- File: `http-client/src/main/java/org/a2aproject/sdk/client/http/A2ACardResolver.java`
- Lines: L80-320
Signature
public class A2ACardResolver {
public static Builder builder();
public AgentCard getAgentCard()
throws A2AClientError, A2AClientJSONError;
public static class Builder {
public Builder httpClient(A2AHttpClient httpClient);
public Builder baseUrl(String baseUrl);
public Builder tenant(@Nullable String tenant);
public Builder agentCardPath(@Nullable String agentCardPath);
public Builder authHeaders(@Nullable Map<String, String> authHeaders);
public Builder authHeader(String name, String value);
public A2ACardResolver build() throws A2AClientError;
}
}
Import
import org.a2aproject.sdk.client.http.A2ACardResolver;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| baseUrl | String | Yes | Agent base URL (e.g., "http://localhost:9999") |
| httpClient | A2AHttpClient | No | Custom HTTP client (default: A2AHttpClientFactory.create()) |
| tenant | String | No | Tenant path for multi-tenant agents |
| agentCardPath | String | No | Custom card path (default: .well-known/agent-card.json) |
| authHeaders | Map<String, String> | No | HTTP authentication headers |
Outputs
| Name | Type | Description |
|---|---|---|
| getAgentCard() returns | AgentCard | Parsed agent capability manifest |
| A2AClientHTTPError | Exception | Non-2xx response (carries status, body, headers) |
| A2AClientError | Exception | Network error fetching card |
| A2AClientJSONError | Exception | Response body not valid AgentCard JSON |
Usage Examples
Basic Card Fetch
import org.a2aproject.sdk.client.http.A2ACardResolver;
import org.a2aproject.sdk.spec.AgentCard;
A2ACardResolver resolver = A2ACardResolver.builder()
.baseUrl("http://localhost:9999")
.build();
AgentCard card = resolver.getAgentCard();
System.out.println("Agent: " + card.name());
System.out.println("Streaming: " + card.capabilities().streaming());
Tenant-Specific Card
A2ACardResolver resolver = A2ACardResolver.builder()
.baseUrl("http://localhost:9999")
.tenant("my-tenant")
.build();
// Fetches from /.well-known/my-tenant/agent-card.json
AgentCard card = resolver.getAgentCard();
Authenticated Card Fetch
A2ACardResolver resolver = A2ACardResolver.builder()
.baseUrl("https://secure-agent.com")
.authHeader("Authorization", "Bearer my-api-token")
.build();
AgentCard card = resolver.getAgentCard();
Via A2A Convenience Method
import org.a2aproject.sdk.A2A;
// Simplest form — uses A2ACardResolver internally
AgentCard card = A2A.getAgentCard("http://localhost:9999");
// With authentication
AgentCard card = A2A.getAgentCard(
"https://secure-agent.com",
null, // default card path
Map.of("Authorization", "Bearer token"));