Skip to main content

A2AMethodRegistry

Struct A2AMethodRegistry 

Source
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

Source

pub fn new() -> Self

Create a new empty registry

Source

pub fn with_agent_card(agent_card: AgentCard) -> Self

Create a registry with agent card

Source

pub fn set_agent_card(&mut self, agent_card: AgentCard)

Set the agent card for this registry

Source

pub fn agent_card(&self) -> Option<&AgentCard>

Get the agent card

Source

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 method
  • handler: Function that handles requests for this method
Source

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.

Source

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 notification
  • handler: Function that handles notifications for this method
Source

pub 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
  • request: The JSON-RPC 2.0 request to handle
§Returns
  • Ok(JsonRpcResponse): Success response from method handler
  • Err(A2AError): Method not found or handler error
Source

pub fn handle_notification( &self, notification: JsonRpcNotification, ) -> A2AResult<()>

Handle a JSON-RPC notification

Looks up the notification handler and executes it.

§Arguments
  • notification: The JSON-RPC 2.0 notification to handle
§Returns
  • Ok(()): Notification handled successfully
  • Err(A2AError): Method not found or handler error
Source

pub fn has_method(&self, method: &str) -> bool

Check if method is registered

Source

pub fn has_notification(&self, method: &str) -> bool

Check if notification is registered

Source

pub fn get_method_metadata(&self, method: &str) -> Option<&MethodMetadata>

Get method metadata

Source

pub fn list_methods(&self) -> Vec<String>

List all registered methods

Source

pub fn list_notifications(&self) -> Vec<String>

List all registered notifications

Source

pub fn get_all_metadata(&self) -> &HashMap<String, MethodMetadata>

Get all method metadata

Source

pub fn unregister_method(&mut self, method: &str) -> bool

Unregister a method

Source

pub fn unregister_notification(&mut self, method: &str) -> bool

Unregister a notification

Source

pub fn clear(&mut self)

Clear all registrations

Source

pub fn stats(&self) -> RegistryStats

Get registry statistics

Trait Implementations§

Source§

impl Default for A2AMethodRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more