mcp
Copyright(C) 2025 Matthias Pall Gissurarson
LicenseMIT
Maintainermpg@mpg.is
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageGHC2021

MCP.Server.Auth

Description

This module provides MCP-compliant OAuth 2.1 authentication with PKCE support.

Synopsis

OAuth Configuration

data OAuthConfig Source #

OAuth configuration for the MCP server

Instances

Instances details
Generic OAuthConfig Source # 
Instance details

Defined in MCP.Server.Auth

Associated Types

type Rep OAuthConfig :: Type -> Type #

Show OAuthConfig Source # 
Instance details

Defined in MCP.Server.Auth

type Rep OAuthConfig Source # 
Instance details

Defined in MCP.Server.Auth

type Rep OAuthConfig = D1 ('MetaData "OAuthConfig" "MCP.Server.Auth" "mcp-0.3.0.0-inplace" 'False) (C1 ('MetaCons "OAuthConfig" 'PrefixI 'True) ((((S1 ('MetaSel ('Just "oauthEnabled") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "oauthProviders") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [OAuthProvider])) :*: (S1 ('MetaSel ('Just "tokenValidationEndpoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: (S1 ('MetaSel ('Just "requireHTTPS") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "authCodeExpirySeconds") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))) :*: ((S1 ('MetaSel ('Just "accessTokenExpirySeconds") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "supportedScopes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text])) :*: (S1 ('MetaSel ('Just "supportedResponseTypes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]) :*: (S1 ('MetaSel ('Just "supportedGrantTypes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]) :*: S1 ('MetaSel ('Just "supportedAuthMethods") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]))))) :*: (((S1 ('MetaSel ('Just "supportedCodeChallengeMethods") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]) :*: S1 ('MetaSel ('Just "autoApproveAuth") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :*: (S1 ('MetaSel ('Just "demoUserIdTemplate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: (S1 ('MetaSel ('Just "demoEmailDomain") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "demoUserName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))) :*: ((S1 ('MetaSel ('Just "publicClientSecret") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "authCodePrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "refreshTokenPrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "clientIdPrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "authorizationSuccessTemplate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))))))))

data OAuthProvider Source #

OAuth provider configuration (MCP-compliant)

Instances

Instances details
Generic OAuthProvider Source # 
Instance details

Defined in MCP.Server.Auth

Associated Types

type Rep OAuthProvider :: Type -> Type #

Show OAuthProvider Source # 
Instance details

Defined in MCP.Server.Auth

type Rep OAuthProvider Source # 
Instance details

Defined in MCP.Server.Auth

data OAuthGrantType Source #

OAuth grant types supported by MCP

Instances

Instances details
Generic OAuthGrantType Source # 
Instance details

Defined in MCP.Server.Auth

Associated Types

type Rep OAuthGrantType :: Type -> Type #

Show OAuthGrantType Source # 
Instance details

Defined in MCP.Server.Auth

Eq OAuthGrantType Source # 
Instance details

Defined in MCP.Server.Auth

type Rep OAuthGrantType Source # 
Instance details

Defined in MCP.Server.Auth

type Rep OAuthGrantType = D1 ('MetaData "OAuthGrantType" "MCP.Server.Auth" "mcp-0.3.0.0-inplace" 'False) (C1 ('MetaCons "AuthorizationCode" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ClientCredentials" 'PrefixI 'False) (U1 :: Type -> Type))

Token Validation

data TokenInfo Source #

Token introspection response

Instances

Instances details
FromJSON TokenInfo Source # 
Instance details

Defined in MCP.Server.Auth

Generic TokenInfo Source # 
Instance details

Defined in MCP.Server.Auth

Associated Types

type Rep TokenInfo :: Type -> Type #

Show TokenInfo Source # 
Instance details

Defined in MCP.Server.Auth

type Rep TokenInfo Source # 
Instance details

Defined in MCP.Server.Auth

validateBearerToken :: MonadIO m => OAuthConfig -> Text -> m (Either Text TokenInfo) Source #

Validate a bearer token

extractBearerToken :: Text -> Maybe Text Source #

Extract Bearer token from Authorization header

PKCE Support

data PKCEChallenge Source #

PKCE challenge data

Instances

Instances details
Generic PKCEChallenge Source # 
Instance details

Defined in MCP.Server.Auth

Associated Types

type Rep PKCEChallenge :: Type -> Type #

Show PKCEChallenge Source # 
Instance details

Defined in MCP.Server.Auth

type Rep PKCEChallenge Source # 
Instance details

Defined in MCP.Server.Auth

type Rep PKCEChallenge = D1 ('MetaData "PKCEChallenge" "MCP.Server.Auth" "mcp-0.3.0.0-inplace" 'False) (C1 ('MetaCons "PKCEChallenge" 'PrefixI 'True) (S1 ('MetaSel ('Just "codeVerifier") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "codeChallenge") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "challengeMethod") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))))

generateCodeVerifier :: IO Text Source #

Generate a cryptographically secure code verifier for PKCE

generateCodeChallenge :: Text -> Text Source #

Generate code challenge from verifier using SHA256 (S256 method)

validateCodeVerifier :: Text -> Text -> Bool Source #

Validate PKCE code verifier against challenge

Metadata Discovery

data OAuthMetadata Source #

OAuth metadata (from discovery endpoint)

Instances

Instances details
FromJSON OAuthMetadata Source # 
Instance details

Defined in MCP.Server.Auth

ToJSON OAuthMetadata Source # 
Instance details

Defined in MCP.Server.Auth

Generic OAuthMetadata Source # 
Instance details

Defined in MCP.Server.Auth

Associated Types

type Rep OAuthMetadata :: Type -> Type #

Show OAuthMetadata Source # 
Instance details

Defined in MCP.Server.Auth

type Rep OAuthMetadata Source # 
Instance details

Defined in MCP.Server.Auth

type Rep OAuthMetadata = D1 ('MetaData "OAuthMetadata" "MCP.Server.Auth" "mcp-0.3.0.0-inplace" 'False) (C1 ('MetaCons "OAuthMetadata" 'PrefixI 'True) (((S1 ('MetaSel ('Just "issuer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "authorizationEndpoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "tokenEndpoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "registrationEndpoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "userInfoEndpoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))))) :*: ((S1 ('MetaSel ('Just "jwksUri") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: (S1 ('MetaSel ('Just "scopesSupported") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe [Text])) :*: S1 ('MetaSel ('Just "responseTypesSupported") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text]))) :*: (S1 ('MetaSel ('Just "grantTypesSupported") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe [Text])) :*: (S1 ('MetaSel ('Just "tokenEndpointAuthMethodsSupported") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe [Text])) :*: S1 ('MetaSel ('Just "codeChallengeMethodsSupported") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe [Text])))))))

discoverOAuthMetadata :: MonadIO m => Text -> m (Either String OAuthMetadata) Source #

Discover OAuth metadata from a well-known endpoint