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 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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AuthContext
impl RefUnwindSafe for AuthContext
impl Send for AuthContext
impl Sync for AuthContext
impl Unpin for AuthContext
impl UnsafeUnpin for AuthContext
impl UnwindSafe for AuthContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more