Skip to main content

ServerInterceptor

Trait ServerInterceptor 

Source
pub trait ServerInterceptor:
    Send
    + Sync
    + 'static {
    // Required methods
    fn before<'a>(
        &'a self,
        ctx: &'a CallContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>;
    fn after<'a>(
        &'a self,
        ctx: &'a CallContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>;
}
Expand description

A server-side interceptor for request processing.

Interceptors run before and after the core handler logic. They can be used for logging, authentication, rate-limiting, or other cross-cutting concerns.

§Object safety

This trait is designed to be used behind Arc<dyn ServerInterceptor>.

Required Methods§

Source

fn before<'a>( &'a self, ctx: &'a CallContext, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>

Called before the request handler processes the method call.

Return Err(...) to abort the request with an error response.

§Errors

Returns an A2aError to reject the request.

Source

fn after<'a>( &'a self, ctx: &'a CallContext, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>

Called after the request handler has finished processing.

This is called even if the handler returned an error. It should not alter the response — use it for logging, metrics, or cleanup.

§Errors

Returns an A2aError if post-processing fails.

Implementors§