pub struct Auth(pub AuthenticatedIdentity);Expand description
Extracts the AuthenticatedIdentity for the current request.
Available inside #[tool], #[resource], and #[prompt] handlers when
the auth feature is enabled and the server is configured with an auth
provider.
Returns McpError::Unauthorized if the request is unauthenticated.
§Example
use mcp_kit::prelude::*;
use mcp_kit::Auth;
#[mcp_kit::tool(description = "A protected tool")]
async fn my_tool(input: String, auth: Auth) -> McpResult<CallToolResult> {
if !auth.has_scope("tools:execute") {
return Err(McpError::Unauthorized("missing scope".into()));
}
Ok(CallToolResult::text(format!("Hello, {}!", auth.subject)))
}Tuple Fields§
§0: AuthenticatedIdentityImplementations§
Methods from Deref<Target = AuthenticatedIdentity>§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Auth
impl RefUnwindSafe for Auth
impl Send for Auth
impl Sync for Auth
impl Unpin for Auth
impl UnsafeUnpin for Auth
impl UnwindSafe for Auth
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