Skip to main content

a2a_protocol_server/
call_context.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F.
3
4//! Call context for server-side interceptors.
5//!
6//! [`CallContext`] carries metadata about the current JSON-RPC or REST call,
7//! allowing [`ServerInterceptor`](crate::ServerInterceptor) implementations
8//! to make access-control and auditing decisions.
9
10/// Metadata about the current server-side method call.
11///
12/// Passed to [`ServerInterceptor::before`](crate::ServerInterceptor::before)
13/// and [`ServerInterceptor::after`](crate::ServerInterceptor::after).
14#[derive(Debug, Clone)]
15pub struct CallContext {
16    /// The JSON-RPC method name (e.g. `"message/send"`).
17    pub method: String,
18
19    /// Optional caller identity extracted from authentication headers.
20    pub caller_identity: Option<String>,
21
22    /// Extension URIs active for this request.
23    pub extensions: Vec<String>,
24}
25
26impl CallContext {
27    /// Creates a new [`CallContext`] for the given method.
28    #[must_use]
29    pub fn new(method: impl Into<String>) -> Self {
30        Self {
31            method: method.into(),
32            caller_identity: None,
33            extensions: Vec::new(),
34        }
35    }
36
37    /// Sets the caller identity.
38    #[must_use]
39    pub fn with_caller_identity(mut self, identity: String) -> Self {
40        self.caller_identity = Some(identity);
41        self
42    }
43
44    /// Sets the active extensions.
45    #[must_use]
46    pub fn with_extensions(mut self, extensions: Vec<String>) -> Self {
47        self.extensions = extensions;
48        self
49    }
50}