Class JSONRPCHandler
This handler converts JSON-RPC 2.0 requests into A2A protocol operations and manages the lifecycle of agent interactions. It supports both blocking request/response and streaming responses via Server-Sent Events.
Request Flow
JSON-RPC requests flow through this handler to the underlying RequestHandler,
which coordinates with the agent executor and event queue system:
JSON-RPC Request → JSONRPCHandler → RequestHandler → AgentExecutor
↓ ↓
Validation EventQueue → Response
JSON-RPC 2.0 Format
Requests follow the JSON-RPC 2.0 specification:
{
"jsonrpc": "2.0",
"id": "request-123",
"method": "sendMessage",
"params": {
"message": {...}
}
}
Responses include the request ID for correlation:
{
"jsonrpc": "2.0",
"id": "request-123",
"result": {
"task": {...}
}
}
Supported Operations
- Message sending (blocking and streaming)
- Task management (get, list, cancel, subscribe)
- Push notification configurations (create, get, list, delete)
Error Handling
All A2A protocol errors are caught and converted to JSON-RPC error responses with the error object embedded in the response. Protocol version and required extensions are validated before processing requests.
Streaming Support
Streaming methods (sendStreamingMessage, subscribeToTask) return
a Flow.Publisher of JSON-RPC responses, allowing Server-Sent Events delivery
when used with Quarkus/Vert.x transport layers.
CDI Integration
This handler is an @ApplicationScoped CDI bean that requires:
AgentCardqualified with@PublicAgentCardRequestHandlerfor processing A2A operationsExecutorqualified with@Internalfor async operations- Optional
AgentCardqualified with@ExtendedAgentCard
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-args constructor for CDI proxy creation.JSONRPCHandler(jakarta.enterprise.inject.Instance<AgentCard> agentCardInstance, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedAgentCard, RequestHandler requestHandler, Executor executor, @Nullable jakarta.enterprise.inject.Instance<AgentCardRouter> agentCardRouterInstance) Creates a JSON-RPC handler with full CDI injection support.JSONRPCHandler(@Nullable AgentCard agentCard, RequestHandler requestHandler, Executor executor) Creates a JSON-RPC handler with basic dependencies. -
Method Summary
Modifier and TypeMethodDescriptionvoidauthorizeTaskAccess(String requestedTaskId, ServerCallContext context, TaskOperation operation) deletePushNotificationConfig(DeleteTaskPushNotificationConfigRequest request, ServerCallContext context) Deletes a push notification configuration.@Nullable AgentCardReturns the public agent card, ornullif no@PublicAgentCardbean is configured.@Nullable AgentCardgetAgentCard(@Nullable String tenant) Returns the public agent card, optionally for a specific tenant.getPushNotificationConfig(GetTaskPushNotificationConfigRequest request, ServerCallContext context) Retrieves a specific push notification configuration.listPushNotificationConfigs(ListTaskPushNotificationConfigsRequest request, ServerCallContext context) Lists push notification configurations for a task.onCancelTask(CancelTaskRequest request, ServerCallContext context) Handles a task cancellation request.onGetExtendedCardRequest(GetExtendedAgentCardRequest request, ServerCallContext context) Retrieves the extended agent card if configured.onGetTask(GetTaskRequest request, ServerCallContext context) Retrieves a specific task by ID.onListTasks(ListTasksRequest request, ServerCallContext context) Lists tasks with optional filtering and pagination.onMessageSend(SendMessageRequest request, ServerCallContext context) Handles a blocking message send request.onMessageSendStream(SendStreamingMessageRequest request, ServerCallContext context) Handles a streaming message send request.onSubscribeToTask(SubscribeToTaskRequest request, ServerCallContext context) Subscribes to task updates via a streaming connection.setPushNotificationConfig(CreateTaskPushNotificationConfigRequest request, ServerCallContext context) Creates a push notification configuration for a task.
-
Constructor Details
-
JSONRPCHandler
protected JSONRPCHandler()No-args constructor for CDI proxy creation. CDI requires a non-private constructor to create proxies for @ApplicationScoped beans. All fields are initialized by the @Inject constructor during actual bean creation. -
JSONRPCHandler
@Inject public JSONRPCHandler(jakarta.enterprise.inject.Instance<AgentCard> agentCardInstance, @Nullable jakarta.enterprise.inject.Instance<AgentCard> extendedAgentCard, RequestHandler requestHandler, Executor executor, @Any @Nullable jakarta.enterprise.inject.Instance<AgentCardRouter> agentCardRouterInstance) Creates a JSON-RPC handler with full CDI injection support.- Parameters:
agentCardInstance- the public agent card instance containing agent capabilitiesextendedAgentCard- optional extended agent card instancerequestHandler- the handler for processing A2A requestsexecutor- the executor for asynchronous operationsagentCardRouterInstance- optional agent card router instance for multitenancy
-
JSONRPCHandler
public JSONRPCHandler(@Nullable AgentCard agentCard, RequestHandler requestHandler, Executor executor) Creates a JSON-RPC handler with basic dependencies.- Parameters:
agentCard- the agent card containing agent capabilities, ornullif no public cardrequestHandler- the handler for processing A2A requestsexecutor- the executor for asynchronous operations
-
-
Method Details
-
onMessageSend
Handles a blocking message send request.This method processes a JSON-RPC
sendMessagerequest containing a message to be sent to the agent. The method blocks until the agent produces a terminal event or requires authentication/input.Example Request:
{ "jsonrpc": "2.0", "id": "msg-123", "method": "sendMessage", "params": { "message": { "parts": [{"text": "What is the weather?"}] } } }Example Response:
{ "jsonrpc": "2.0", "id": "msg-123", "result": { "task": { "id": "task-456", "status": {"state": "COMPLETED"}, "artifacts": [...] } } }- Parameters:
request- the JSON-RPC request containing message paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with task or message result
- See Also:
-
onMessageSendStream
public Flow.Publisher<SendStreamingMessageResponse> onMessageSendStream(SendStreamingMessageRequest request, ServerCallContext context) Handles a streaming message send request.This method processes a JSON-RPC
sendStreamingMessagerequest for streaming responses from the agent. The response is returned as aFlow.Publisherof JSON-RPC response objects, allowing Server-Sent Events delivery.This method requires the agent card to have
capabilities.streaming = true.Example Request:
{ "jsonrpc": "2.0", "id": "stream-123", "method": "sendStreamingMessage", "params": { "message": { "parts": [{"text": "Generate a story"}] } } }Example Streaming Responses:
{"jsonrpc":"2.0","id":"stream-123","result":{"taskStatusUpdate":{...}}} {"jsonrpc":"2.0","id":"stream-123","result":{"taskArtifactUpdate":{...}}} {"jsonrpc":"2.0","id":"stream-123","result":{"taskStatusUpdate":{...}}}- Parameters:
request- the JSON-RPC request containing message paramscontext- the server call context containing authentication and metadata- Returns:
- publisher of JSON-RPC response objects containing streaming events
- See Also:
-
onCancelTask
Handles a task cancellation request.Attempts to cancel a running task identified by the task ID in the request params. The cancellation request is forwarded to the
RequestHandler, which signals the agent executor to stop processing. The agent should transition the task toCANCELEDstate.Example Request:
{ "jsonrpc": "2.0", "id": "cancel-123", "method": "cancelTask", "params": { "taskId": "task-456" } }- Parameters:
request- the JSON-RPC request containing task ID paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with the cancelled task
- See Also:
-
onSubscribeToTask
public Flow.Publisher<SendStreamingMessageResponse> onSubscribeToTask(SubscribeToTaskRequest request, ServerCallContext context) throws A2AError Subscribes to task updates via a streaming connection.Creates a stream that delivers real-time updates for an existing task. This allows clients to reconnect to ongoing or completed tasks and receive their event history and future updates.
This method requires the agent card to have
capabilities.streaming = true.Example Request:
{ "jsonrpc": "2.0", "id": "subscribe-123", "method": "subscribeToTask", "params": { "taskId": "task-456" } }Use Cases:
- Reconnecting to a task after network interruption
- Monitoring long-running tasks from multiple clients
- Viewing historical events for completed tasks
- Parameters:
request- the JSON-RPC request containing task ID paramscontext- the server call context containing authentication and metadata- Returns:
- publisher of JSON-RPC response objects containing task updates
- Throws:
A2AError- See Also:
-
getPushNotificationConfig
public GetTaskPushNotificationConfigResponse getPushNotificationConfig(GetTaskPushNotificationConfigRequest request, ServerCallContext context) Retrieves a specific push notification configuration.Returns the push notification configuration for a task by config ID. This method requires the agent card to have
capabilities.pushNotifications = true.Example Request:
{ "jsonrpc": "2.0", "id": "get-config-123", "method": "getTaskPushNotificationConfig", "params": { "taskId": "task-456", "configId": "config-789" } }- Parameters:
request- the JSON-RPC request containing task and config ID paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with the configuration
- See Also:
-
setPushNotificationConfig
public CreateTaskPushNotificationConfigResponse setPushNotificationConfig(CreateTaskPushNotificationConfigRequest request, ServerCallContext context) Creates a push notification configuration for a task.Creates a new push notification configuration specifying webhook URL and event filters. This method requires the agent card to have
capabilities.pushNotifications = true.Example Request:
{ "jsonrpc": "2.0", "id": "create-config-123", "method": "setTaskPushNotificationConfig", "params": { "taskId": "task-456", "url": "https://webhook.example.com/notify", "events": ["taskStatusUpdate", "taskArtifactUpdate"] } }- Parameters:
request- the JSON-RPC request containing push notification config paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with the created configuration
- See Also:
-
onGetTask
Retrieves a specific task by ID.Returns the complete task object including status, artifacts, and optionally task history based on the
historyLengthparameter.Example Request:
{ "jsonrpc": "2.0", "id": "get-123", "method": "getTask", "params": { "taskId": "task-456", "historyLength": 10 } }- Parameters:
request- the JSON-RPC request containing task query paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with the task object
- See Also:
-
onListTasks
Lists tasks with optional filtering and pagination.Retrieves a list of tasks with support for filtering by context, status, and timestamp, along with pagination controls.
Example Request:
{ "jsonrpc": "2.0", "id": "list-123", "method": "listTasks", "params": { "status": "COMPLETED", "pageSize": 10, "includeArtifacts": true } }Query Parameters:
contextId- Filter tasks by conversation contextstatus- Filter by task statepageSize- Maximum tasks to returnpageToken- Token for paginationhistoryLength- Max history entries per taskstatusTimestampAfter- ISO-8601 timestamp filterincludeArtifacts- Include task artifacts
- Parameters:
request- the JSON-RPC request containing list tasks paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with list of tasks
- See Also:
-
listPushNotificationConfigs
public ListTaskPushNotificationConfigsResponse listPushNotificationConfigs(ListTaskPushNotificationConfigsRequest request, ServerCallContext context) Lists push notification configurations for a task.Returns a paginated list of push notification configurations associated with a task. This method requires the agent card to have
capabilities.pushNotifications = true.Example Request:
{ "jsonrpc": "2.0", "id": "list-config-123", "method": "listTaskPushNotificationConfigs", "params": { "taskId": "task-456", "pageSize": 10 } }- Parameters:
request- the JSON-RPC request containing task ID and pagination paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with list of configurations
- See Also:
-
deletePushNotificationConfig
public DeleteTaskPushNotificationConfigResponse deletePushNotificationConfig(DeleteTaskPushNotificationConfigRequest request, ServerCallContext context) Deletes a push notification configuration.Removes a push notification configuration by config ID, stopping notifications for the associated task. This method requires the agent card to have
capabilities.pushNotifications = true.Example Request:
{ "jsonrpc": "2.0", "id": "delete-config-123", "method": "deleteTaskPushNotificationConfig", "params": { "taskId": "task-456", "configId": "config-789" } }- Parameters:
request- the JSON-RPC request containing task and config ID paramscontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response confirming deletion
- See Also:
-
onGetExtendedCardRequest
public GetExtendedAgentCardResponse onGetExtendedCardRequest(GetExtendedAgentCardRequest request, ServerCallContext context) Retrieves the extended agent card if configured.The extended agent card provides additional metadata beyond the public agent card, such as tenant-specific configurations or private capabilities. This endpoint requires the agent card to have
capabilities.extendedAgentCard = trueand a CDI-produced@ExtendedAgentCardinstance.Example Request:
{ "jsonrpc": "2.0", "id": "ext-card-123", "method": "getExtendedAgentCard", "params": {} }- Parameters:
request- the JSON-RPC request for extended agent cardcontext- the server call context containing authentication and metadata- Returns:
- JSON-RPC response with the extended agent card
- See Also:
-
getAgentCard
Returns the public agent card, ornullif no@PublicAgentCardbean is configured.The agent card is a self-describing manifest that provides essential metadata about the agent, including its capabilities, supported skills, communication methods, and security requirements.
- Returns:
- the public agent card, or
nullif not configured - See Also:
-
getAgentCard
Returns the public agent card, optionally for a specific tenant.When a tenant is specified and an
AgentCardRouteris available, the router resolves the card. If the router returnsnullthe tenant is unknown and aTenantNotFoundExceptionis thrown (callers should map this to HTTP 404).When no router is configured, any non-blank tenant is logged and the default card is returned (single-tenant server, tenant segment is ignored).
- Parameters:
tenant- the tenant identifier, may benull- Returns:
- the public agent card, or
nullif no@PublicAgentCardbean is configured - Throws:
TenantNotFoundException- if a router is configured but the tenant is not registered
-
authorizeTaskAccess
public void authorizeTaskAccess(String requestedTaskId, ServerCallContext context, TaskOperation operation)
-