registry
A2A Method Registry
Manages registration and lookup of A2A protocol methods. This module provides the core registry functionality without any transport or infrastructure dependencies.
Type Aliases
Section titled “Type Aliases”A2AMethodHandler
Section titled “A2AMethodHandler”type A2AMethodHandler = Arc<dyn Fn + Send + Sync>;A2A Method Handler function type
Handlers receive a JSON-RPC request and return a JSON-RPC response. All A2A protocol logic is handled through JSON-RPC 2.0 messages.
A2ANotificationHandler
Section titled “A2ANotificationHandler”type A2ANotificationHandler = Arc<dyn Fn + Send + Sync>;A2A Notification Handler function type
Notification handlers receive notifications and perform side effects without returning responses (fire-and-forget).
Structs
Section titled “Structs”MethodMetadata
Section titled “MethodMetadata”Method metadata
Contains information about a registered method including its description, parameters, and capabilities.
Fields
| Field | Type | Description |
|---|---|---|
name | String | |
description | String | |
parameters | Option<serde_json::Value> | |
returns | Option<serde_json::Value> | |
is_notification | bool |
A2AMethodRegistry
Section titled “A2AMethodRegistry”A2A Method Registry
Central registry for A2A protocol methods and their handlers. Provides method registration, lookup, and validation functionality without any transport dependencies.
Design Principles
Section titled “Design Principles”- Pure Domain Logic: No transport or infrastructure concerns
- JSON-RPC Foundation: All methods use JSON-RPC 2.0 message types
- Thread Safe: Can be safely shared across multiple threads
- Method Metadata: Rich metadata for discovery and documentation
Examples
Section titled “Examples”use a2a_protocol_core::{A2AMethodRegistry, JsonRpcRequest, JsonRpcResponse, A2AError};use serde_json::json;use std::sync::Arc;
fn example() -> Result<(), A2AError> { let mut registry = A2AMethodRegistry::new();
// Register a method handler registry.register_method( "ping", "Simple ping method", Arc::new(|request| { Ok(JsonRpcResponse::success(request.id, json!({"pong": true}))) }) );
// Handle requests let request = JsonRpcRequest::new(json!("req-123"), "ping".to_string(), json!({})); let response = registry.handle_request(request)?; Ok(())}Methods
fn new() -> SelfCreate a new empty registry
with_agent_card
Section titled “with_agent_card”fn with_agent_card(agent_card: AgentCard) -> SelfCreate a registry with agent card
set_agent_card
Section titled “set_agent_card”fn set_agent_card(&mut self, agent_card: AgentCard)Set the agent card for this registry
agent_card
Section titled “agent_card”fn agent_card(&self) -> Option<&AgentCard>Get the agent card
register_method
Section titled “register_method”fn register_method<impl Into<String>, impl Into<String>>(&mut self, method: impl Into, description: impl Into, handler: A2AMethodHandler)Register a method handler
Registers a handler function for JSON-RPC requests to the specified method.
Arguments
Section titled “Arguments”method: Method name (e.g., “ping”, “process_data”)description: Human-readable description of the methodhandler: Function that handles requests for this method
register_method_with_metadata
Section titled “register_method_with_metadata”fn register_method_with_metadata<impl Into<String>, impl Into<String>>(&mut self, method: impl Into, description: impl Into, parameters: Option<Value>, returns: Option<Value>, handler: A2AMethodHandler)Register a method handler with metadata
Registers a method handler with detailed parameter and return type information.
register_notification
Section titled “register_notification”fn register_notification<impl Into<String>, impl Into<String>>(&mut self, method: impl Into, description: impl Into, handler: A2ANotificationHandler)Register a notification handler
Registers a handler function for JSON-RPC notifications (fire-and-forget).
Arguments
Section titled “Arguments”method: Method name (e.g., “log.info”, “metric.counter”)description: Human-readable description of the notificationhandler: Function that handles notifications for this method
handle_request
Section titled “handle_request”fn handle_request(&self, request: JsonRpcRequest) -> A2AResult<JsonRpcResponse>Handle a JSON-RPC request
Looks up the method handler and executes it with the request.
Arguments
Section titled “Arguments”request: The JSON-RPC 2.0 request to handle
Returns
Section titled “Returns”Ok(JsonRpcResponse): Success response from method handlerErr(A2AError): Method not found or handler error
handle_notification
Section titled “handle_notification”fn handle_notification(&self, notification: JsonRpcNotification) -> A2AResult<()>Handle a JSON-RPC notification
Looks up the notification handler and executes it.
Arguments
Section titled “Arguments”notification: The JSON-RPC 2.0 notification to handle
Returns
Section titled “Returns”Ok(()): Notification handled successfullyErr(A2AError): Method not found or handler error
has_method
Section titled “has_method”fn has_method(&self, method: &str) -> boolCheck if method is registered
has_notification
Section titled “has_notification”fn has_notification(&self, method: &str) -> boolCheck if notification is registered
get_method_metadata
Section titled “get_method_metadata”fn get_method_metadata(&self, method: &str) -> Option<&MethodMetadata>Get method metadata
list_methods
Section titled “list_methods”fn list_methods(&self) -> Vec<String>List all registered methods
list_notifications
Section titled “list_notifications”fn list_notifications(&self) -> Vec<String>List all registered notifications
get_all_metadata
Section titled “get_all_metadata”fn get_all_metadata(&self) -> &HashMap<String, MethodMetadata>Get all method metadata
unregister_method
Section titled “unregister_method”fn unregister_method(&mut self, method: &str) -> boolUnregister a method
unregister_notification
Section titled “unregister_notification”fn unregister_notification(&mut self, method: &str) -> boolUnregister a notification
fn clear(&mut self)Clear all registrations
fn stats(&self) -> RegistryStatsGet registry statistics
RegistryStats
Section titled “RegistryStats”Registry statistics
Fields
| Field | Type | Description |
|---|---|---|
method_count | usize | |
notification_count | usize | |
total_registrations | usize |