Skip to main content

CallContext

Struct CallContext 

Source
pub struct CallContext { /* private fields */ }
Expand description

Metadata about the current server-side method call.

Passed to ServerInterceptor::before and ServerInterceptor::after.

Implementations§

Source§

impl CallContext

Source

pub fn method(&self) -> &str

Returns the JSON-RPC method name.

Source

pub fn caller_identity(&self) -> Option<&str>

Returns the caller identity, once something has established one.

Source

pub fn set_caller_identity(&self, identity: impl Into<String>) -> bool

Records who the caller is, if nothing has yet.

Returns true when this call set the identity and false when one was already present — in which case the existing identity stands and the argument is dropped.

Takes &self deliberately: the caller is established by an authentication interceptor, and ServerInterceptor::before receives a shared reference. Anything that needs &mut here is unreachable from the place that has the answer.

§Example
use a2a_protocol_server::CallContext;

let ctx = CallContext::new("SendMessage");
assert!(ctx.set_caller_identity("[email protected]"));
assert_eq!(ctx.caller_identity(), Some("[email protected]"));

// A second interceptor does not get to overwrite it.
assert!(!ctx.set_caller_identity("someone-else"));
assert_eq!(ctx.caller_identity(), Some("[email protected]"));
Source

pub fn auth_scheme(&self) -> Option<&str>

Returns how the caller was authenticated, once something has said.

The bundled interceptors set "api-key", "bearer" and "jwt". The audit log records it beside the identity, so a record says not only who but on what evidence.

Source

pub fn set_auth_scheme(&self, scheme: impl Into<String>) -> bool

Records how the caller was authenticated, if nothing has yet; returns whether this call set it. Set it beside set_caller_identity in a custom authentication interceptor.

Source

pub fn actors(&self) -> &[String]

The agents acting for the caller, nearest first, when the caller’s credential names them: the RFC 8693 act chain of a delegated token (ADR 0021), each as caller_id::jwt. The caller_identity is then the principal the work is for. Empty when nothing named an actor.

Source

pub fn set_actors(&self, actors: Vec<String>) -> bool

Records the actors, if nothing has yet; returns whether this call set them. An authentication interceptor sets them beside the identity.

Source

pub fn extensions(&self) -> &[String]

Returns the active extension URIs.

Source

pub fn request_id(&self) -> Option<&str>

Returns the request/trace ID if set.

Source

pub const fn http_headers(&self) -> &HashMap<String, String>

Returns the HTTP request headers (read-only).

Source

pub const fn trace_context(&self) -> Option<&TraceContext>

The W3C trace this call belongs to, when the caller propagated one.

None means the caller sent no traceparent, or sent one this SDK refused. It never means “we made one up”: the server propagates traces and does not start them, so a Some here is evidence that something upstream is actually tracing.

Source

pub fn tenant(&self) -> Option<&str>

Returns the tenant this call resolved to, if any.

Prefer this over TenantContext::current anywhere the value has to survive a tokio::spawn: the task-local is not inherited by a spawned task, and this field is an owned copy taken before the spawn.

Source

pub fn peer_addr(&self) -> Option<SocketAddr>

The address of the connection this call arrived on, when the binding knew it; see the module docs.

Read from the headers map’s PEER_ADDR_KEY entry; None when there is none or it does not parse as a socket address.

Source

pub fn peer_certificate(&self) -> Option<Vec<u8>>

The DER encoding of the certificate the client presented in a mutual-TLS handshake on this listener, when it presented one; see the module docs.

Read from the headers map’s PEER_CERTIFICATE_KEY entry; None when there is none or it is not base64.

Source

pub fn task_id(&self) -> Option<&str>

The task this request names, as the caller sent it: the id of GetTask, CancelTask and SubscribeToTask, the taskId of a push-config operation, or the taskId of a SendMessage continuing a task. None for a request that names no task (ListTasks, a message starting a new task, GetExtendedAgentCard).

Set before the interceptor chain runs, so an authorizer can decide per task (spec §13.1: “Servers MUST implement authorization checks on every A2A Protocol Operations request”) and refuse with A2aError::permission_denied. It is not yet checked: the task may not exist, or may belong to another caller, in which case the operation answers TaskNotFound after the chain admits it.

Source§

impl CallContext

Source

pub fn new(method: impl Into<String>) -> CallContext

Creates a new CallContext for the given method.

Source

pub fn call_id(&self) -> &str

A random identifier for this call, made by the server when the context is built: unlike request_id, which the caller chooses, it is unique to this call and cannot be supplied or repeated by a client. The audit log writes it on a call’s call.started and call records, so the end of a call can be matched to its start.

Source

pub const fn received_at(&self) -> Instant

When this call context was built, which the handler does as the request arrives, before interceptors, locks and admission waits. A caller’s budget is timed from here (ADR 0023).

Source

pub fn with_trace_context(self, trace_context: TraceContext) -> CallContext

Sets the trace this call belongs to.

Source

pub fn with_task_id(self, task_id: impl Into<String>) -> CallContext

Sets the task the request names; see task_id.

Source

pub fn with_tenant(self, tenant: impl Into<String>) -> CallContext

Sets the resolved tenant.

Source

pub fn with_caller_identity(self, identity: String) -> CallContext

Sets the caller identity at construction.

For a caller building a context directly. An interceptor holding &CallContext wants set_caller_identity.

Source

pub fn with_extensions(self, extensions: Vec<String>) -> CallContext

Sets the active extensions.

Source

pub fn with_request_id(self, id: impl Into<String>) -> CallContext

Sets the request/trace ID explicitly.

Source

pub fn with_peer_addr(self, addr: SocketAddr) -> CallContext

Sets the address of the connection the call arrived on (the PEER_ADDR_KEY entry of the headers map).

Source

pub fn with_peer_certificate(self, der: &[u8]) -> CallContext

Sets the certificate the client presented (the PEER_CERTIFICATE_KEY entry of the headers map), DER-encoded.

Source

pub fn with_http_headers(self, headers: HashMap<String, String>) -> CallContext

Sets the HTTP headers map (replacing any existing headers).

Automatically extracts x-request-id into request_id if present.

Source

pub fn with_http_header( self, key: impl Into<String>, value: impl Into<String>, ) -> CallContext

Adds a single HTTP header (key is lowercased for case-insensitive matching).

If the key is x-request-id, also populates request_id.

Trait Implementations§

Source§

impl Clone for CallContext

Source§

fn clone(&self) -> CallContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CallContext

Hand-written so a caller’s credentials cannot reach a log through a debug-print.

Until 0.13.0 CallContext reached only the interceptor chain. It now rides on RequestContext into every AgentExecutor, and the derived Debug printed http_headers verbatim — Authorization, Cookie, whatever the deployment forwards. tracing::debug!("{ctx:?}") inside an executor is a natural thing to write, and the executor is the component most likely to be LLM-adjacent or to forward its context somewhere else.

Header names are printed and values are not, rather than redacting a named list of sensitive ones: a denylist rots the moment a deployment forwards a header nobody thought of, and the names alone answer the question a debug-print is usually asking. Read a value deliberately with http_header when you want one.

This is the same call auth::jwt already makes for its signing secret.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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