Skip to main content

Module auth

Module auth 

Source
Expand description

Authentication support for MCP servers.

This module provides the core auth abstractions used across all transports. Each auth scheme is gated behind a feature flag so you only compile what you use:

FeatureProviderCredential type
auth-bearerBearerTokenProviderAuthorization: Bearer <token>
auth-apikeyApiKeyProviderX-Api-Key: <key> or ?api_key=
auth-basicBasicAuthProviderAuthorization: Basic <b64>
auth-oauth2[OAuth2Provider]Bearer token (introspection or JWT/JWKS)
auth-mtls[MtlsProvider]Client certificate (mTLS)
(always)CustomHeaderProviderAny custom header
(always)CompositeAuthProviderTry multiple providers in order

§Quick start

use mcp_kit::auth::{BearerTokenProvider, CompositeAuthProvider};
use mcp_kit::auth::composite::IntoDynProvider;

let provider = CompositeAuthProvider::new(vec![
    BearerTokenProvider::new(["my-secret"]).into_dyn(),
]);

Re-exports§

pub use composite::CompositeAuthProvider;
pub use composite::IntoDynProvider;
pub use credentials::Credentials;
pub use custom::CustomHeaderProvider;
pub use identity::AuthenticatedIdentity;
pub use provider::AuthFuture;
pub use provider::AuthProvider;
pub use provider::DynAuthProvider;
pub use bearer::BearerTokenProvider;
pub use apikey::ApiKeyProvider;
pub use basic::BasicAuthProvider;

Modules§

apikey
basic
bearer
composite
credentials
custom
identity
provider