pub struct A2AMethodRegistry { /* private fields */ }Expand description
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
- 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
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(())
}Implementations§
Source§impl A2AMethodRegistry
impl A2AMethodRegistry
Sourcepub fn with_agent_card(agent_card: AgentCard) -> Self
pub fn with_agent_card(agent_card: AgentCard) -> Self
Create a registry with agent card
Sourcepub fn set_agent_card(&mut self, agent_card: AgentCard)
pub fn set_agent_card(&mut self, agent_card: AgentCard)
Set the agent card for this registry
Sourcepub fn agent_card(&self) -> Option<&AgentCard>
pub fn agent_card(&self) -> Option<&AgentCard>
Get the agent card
Sourcepub fn register_method(
&mut self,
method: impl Into<String>,
description: impl Into<String>,
handler: A2AMethodHandler,
)
pub fn register_method( &mut self, method: impl Into<String>, description: impl Into<String>, handler: A2AMethodHandler, )
Register a method handler
Registers a handler function for JSON-RPC requests to the specified method.
§Arguments
method: Method name (e.g., “ping”, “process_data”)description: Human-readable description of the methodhandler: Function that handles requests for this method
Sourcepub fn register_method_with_metadata(
&mut self,
method: impl Into<String>,
description: impl Into<String>,
parameters: Option<Value>,
returns: Option<Value>,
handler: A2AMethodHandler,
)
pub fn register_method_with_metadata( &mut self, method: impl Into<String>, description: impl Into<String>, 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.
Sourcepub fn register_notification(
&mut self,
method: impl Into<String>,
description: impl Into<String>,
handler: A2ANotificationHandler,
)
pub fn register_notification( &mut self, method: impl Into<String>, description: impl Into<String>, handler: A2ANotificationHandler, )
Register a notification handler
Registers a handler function for JSON-RPC notifications (fire-and-forget).
§Arguments
method: Method name (e.g., “log.info”, “metric.counter”)description: Human-readable description of the notificationhandler: Function that handles notifications for this method
Sourcepub fn handle_request(
&self,
request: JsonRpcRequest,
) -> A2AResult<JsonRpcResponse>
pub fn handle_request( &self, request: JsonRpcRequest, ) -> A2AResult<JsonRpcResponse>
Sourcepub fn handle_notification(
&self,
notification: JsonRpcNotification,
) -> A2AResult<()>
pub fn handle_notification( &self, notification: JsonRpcNotification, ) -> A2AResult<()>
Sourcepub fn has_method(&self, method: &str) -> bool
pub fn has_method(&self, method: &str) -> bool
Check if method is registered
Sourcepub fn has_notification(&self, method: &str) -> bool
pub fn has_notification(&self, method: &str) -> bool
Check if notification is registered
Sourcepub fn get_method_metadata(&self, method: &str) -> Option<&MethodMetadata>
pub fn get_method_metadata(&self, method: &str) -> Option<&MethodMetadata>
Get method metadata
Sourcepub fn list_methods(&self) -> Vec<String>
pub fn list_methods(&self) -> Vec<String>
List all registered methods
Sourcepub fn list_notifications(&self) -> Vec<String>
pub fn list_notifications(&self) -> Vec<String>
List all registered notifications
Sourcepub fn get_all_metadata(&self) -> &HashMap<String, MethodMetadata>
pub fn get_all_metadata(&self) -> &HashMap<String, MethodMetadata>
Get all method metadata
Sourcepub fn unregister_method(&mut self, method: &str) -> bool
pub fn unregister_method(&mut self, method: &str) -> bool
Unregister a method
Sourcepub fn unregister_notification(&mut self, method: &str) -> bool
pub fn unregister_notification(&mut self, method: &str) -> bool
Unregister a notification
Sourcepub fn stats(&self) -> RegistryStats
pub fn stats(&self) -> RegistryStats
Get registry statistics