pub struct AuthContext { /* private fields */ }Expand description
Per-request authorization context.
Built by middleware (e.g. from JWT claims) and stored in rmcp’s
RequestContext::extensions. Use rmcp’s Extension<AuthContext>
extractor to access it in tool handlers.
use mcp_authorization::{AuthContext, Capability, Proof};
struct BackwardRouting;
impl Capability for BackwardRouting {
const NAME: &'static str = "backward_routing";
}
let auth = AuthContext::new(vec!["backward_routing"]);
let proof: Proof<BackwardRouting> = auth.require::<BackwardRouting>().unwrap();Implementations§
Source§impl AuthContext
impl AuthContext
Sourcepub fn new(caps: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn new(caps: impl IntoIterator<Item = impl Into<String>>) -> Self
Create a new AuthContext from an iterable of capability names.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
An AuthContext with no capabilities — the deny-by-default identity.
A request resolved to an empty context sees only ungated tools, never
any tool guarded by authorize or
any #[requires(...)] field/variant.
Sourcepub fn check<C: Capability>(&self) -> Option<Proof<C>>
pub fn check<C: Capability>(&self) -> Option<Proof<C>>
Try to obtain a Proof<C>. Returns Some(Proof) if the user has
the capability, None otherwise.
This is the only way to construct a Proof<C>.
Sourcepub fn require<C: Capability>(&self) -> Result<Proof<C>, ErrorData>
pub fn require<C: Capability>(&self) -> Result<Proof<C>, ErrorData>
Like check, but returns an McpError on failure.
Sourcepub fn has(&self, name: &str) -> bool
pub fn has(&self, name: &str) -> bool
String-based capability query for runtime schema shaping.
Sourcepub fn capability_names(&self) -> &HashSet<String>
pub fn capability_names(&self) -> &HashSet<String>
Returns the set of capability names this context holds.
Trait Implementations§
Source§impl Clone for AuthContext
impl Clone for AuthContext
Source§fn clone(&self) -> AuthContext
fn clone(&self) -> AuthContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more