auth
MCP Authentication
Section titled “MCP Authentication”OAuth 2.1 Bearer token authentication for MCP protocol
- Standard Authorization header handling
- Custom authentication strategies support
- External MCP server authentication
Traits
Section titled “Traits”AuthHandler
Section titled “AuthHandler”Authentication Handler Trait
Required / Provided Methods
fn validate_request(&self, request: &UniversalRequest) -> Result<(), ProtocolError>Validate request authentication
fn add_auth_headers(&self, request: &mut UniversalRequest) -> Result<(), ProtocolError>Add authentication to outgoing request
Structs
Section titled “Structs”BearerAuthHandler
Section titled “BearerAuthHandler”Bearer Token Authentication Handler
Methods
fn new() -> SelfCreate new bearer auth handler
with_required_token
Section titled “with_required_token”fn with_required_token(self, token: &str) -> SelfConfigure required token for server mode
with_client_token
Section titled “with_client_token”fn with_client_token(self, token: BearerToken) -> SelfConfigure client token for outgoing requests
NoAuthHandler
Section titled “NoAuthHandler”No Authentication Handler - Allows all requests
CustomAuthHandler
Section titled “CustomAuthHandler”Custom Authentication Handler - User-defined validation
Methods
fn new(validate_fn: F, add_auth_fn: G) -> SelfCreate custom auth handler with validation and auth addition functions
AuthBuilder
Section titled “AuthBuilder”Authentication Builder - Convenient auth handler creation
Methods
fn none() -> NoAuthHandlerCreate no authentication handler
bearer_server
Section titled “bearer_server”fn bearer_server(required_token: &str) -> BearerAuthHandlerCreate bearer token auth for server
bearer_client
Section titled “bearer_client”fn bearer_client(token: &str) -> BearerAuthHandlerCreate bearer token auth for client
bearer_both
Section titled “bearer_both”fn bearer_both(required_token: &str, client_token: &str) -> BearerAuthHandlerCreate bearer token auth for both server and client