Skip to content

auth

OAuth 2.1 Bearer token authentication for MCP protocol

  • Standard Authorization header handling
  • Custom authentication strategies support
  • External MCP server authentication

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

Bearer Token Authentication Handler

Methods

fn new() -> Self

Create new bearer auth handler

fn with_required_token(self, token: &str) -> Self

Configure required token for server mode

fn with_client_token(self, token: BearerToken) -> Self

Configure client token for outgoing requests

No Authentication Handler - Allows all requests

Custom Authentication Handler - User-defined validation

Methods

fn new(validate_fn: F, add_auth_fn: G) -> Self

Create custom auth handler with validation and auth addition functions

Authentication Builder - Convenient auth handler creation

Methods

fn none() -> NoAuthHandler

Create no authentication handler

fn bearer_server(required_token: &str) -> BearerAuthHandler

Create bearer token auth for server

fn bearer_client(token: &str) -> BearerAuthHandler

Create bearer token auth for client

fn bearer_both(required_token: &str, client_token: &str) -> BearerAuthHandler

Create bearer token auth for both server and client