|
1 |
| -from .models.auth_server import AuthServerConfig |
| 1 | +from enum import Enum |
| 2 | +from typing import List, Optional |
2 | 3 | from pydantic import BaseModel
|
3 | 4 |
|
4 | 5 |
|
5 |
| -class MCPAuthConfig(BaseModel): |
| 6 | +class AuthorizationServerMetadata(BaseModel): |
6 | 7 | """
|
7 |
| - Configuration for the `MCPAuth` class. |
| 8 | + Pydantic model for OAuth 2.0 Authorization Server Metadata as defined in RFC 8414. |
8 | 9 | """
|
9 | 10 |
|
10 |
| - server: AuthServerConfig |
| 11 | + issuer: str |
11 | 12 | """
|
12 |
| - Config for the remote authorization server. |
| 13 | + The authorization server's issuer identifier, which is a URL that uses the `https` scheme and |
| 14 | + has no query or fragment components. |
13 | 15 | """
|
| 16 | + |
| 17 | + authorization_endpoint: str |
| 18 | + """ |
| 19 | + URL of the authorization server's authorization endpoint [[RFC6749](https://rfc-editor.org/rfc/rfc6749)]. |
| 20 | + This is REQUIRED unless no grant types are supported that use the authorization endpoint. |
| 21 | +
|
| 22 | + See: https://rfc-editor.org/rfc/rfc6749#section-3.1 |
| 23 | + """ |
| 24 | + |
| 25 | + token_endpoint: str |
| 26 | + """ |
| 27 | + URL of the authorization server's token endpoint [[RFC6749](https://rfc-editor.org/rfc/rfc6749)]. |
| 28 | + This is REQUIRED unless only the implicit grant type is supported. |
| 29 | +
|
| 30 | + See: https://rfc-editor.org/rfc/rfc6749#section-3.2 |
| 31 | + """ |
| 32 | + |
| 33 | + jwks_uri: Optional[str] = None |
| 34 | + """ |
| 35 | + URL of the authorization server's JWK Set [[JWK](https://www.rfc-editor.org/rfc/rfc8414.html#ref-JWK)] document. |
| 36 | + The referenced document contains the signing key(s) the client uses to validate signatures |
| 37 | + from the authorization server. This URL MUST use the `https` scheme. |
| 38 | + """ |
| 39 | + |
| 40 | + registration_endpoint: Optional[str] = None |
| 41 | + """ |
| 42 | + URL of the authorization server's OAuth 2.0 Dynamic Client Registration endpoint |
| 43 | + [[RFC7591](https://www.rfc-editor.org/rfc/rfc7591)]. |
| 44 | + """ |
| 45 | + |
| 46 | + scope_supported: Optional[List[str]] = None |
| 47 | + |
| 48 | + response_types_supported: List[str] |
| 49 | + """ |
| 50 | + JSON array containing a list of the OAuth 2.0 `response_type` values that this authorization |
| 51 | + server supports. The array values used are the same as those used with the `response_types` |
| 52 | + parameter defined by "OAuth 2.0 Dynamic Client Registration Protocol" [[RFC7591](https://www.rfc-editor.org/rfc/rfc7591)]. |
| 53 | + """ |
| 54 | + |
| 55 | + response_modes_supported: Optional[List[str]] = None |
| 56 | + """ |
| 57 | + JSON array containing a list of the OAuth 2.0 `response_mode` values that this |
| 58 | + authorization server supports, as specified in "OAuth 2.0 Multiple Response Type Encoding Practices" |
| 59 | + [[OAuth.Responses](https://datatracker.ietf.org/doc/html/rfc8414#ref-OAuth.Responses)]. |
| 60 | +
|
| 61 | + If omitted, the default is ["query", "fragment"]. The response mode value `"form_post"` is |
| 62 | + also defined in "OAuth 2.0 Form Post Response Mode" [[OAuth.FormPost](https://datatracker.ietf.org/doc/html/rfc8414#ref-OAuth.Post)]. |
| 63 | + """ |
| 64 | + |
| 65 | + grant_types_supported: Optional[List[str]] = None |
| 66 | + """ |
| 67 | + JSON array containing a list of the OAuth 2.0 grant type values that this authorization server supports. |
| 68 | + The array values used are the same as those used with the `grant_types` parameter defined by |
| 69 | + "OAuth 2.0 Dynamic Client Registration Protocol" [[RFC7591](https://www.rfc-editor.org/rfc/rfc7591)]. |
| 70 | +
|
| 71 | + If omitted, the default value is ["authorization_code", "implicit"]. |
| 72 | + """ |
| 73 | + |
| 74 | + token_endpoint_auth_methods_supported: Optional[List[str]] = None |
| 75 | + token_endpoint_auth_signing_alg_values_supported: Optional[List[str]] = None |
| 76 | + service_documentation: Optional[str] = None |
| 77 | + ui_locales_supported: Optional[List[str]] = None |
| 78 | + op_policy_uri: Optional[str] = None |
| 79 | + op_tos_uri: Optional[str] = None |
| 80 | + |
| 81 | + revocation_endpoint: Optional[str] = None |
| 82 | + """ |
| 83 | + URL of the authorization server's OAuth 2.0 revocation endpoint [[RFC7009](https://www.rfc-editor.org/rfc/rfc7009)]. |
| 84 | + """ |
| 85 | + |
| 86 | + revocation_endpoint_auth_methods_supported: Optional[List[str]] = None |
| 87 | + revocation_endpoint_auth_signing_alg_values_supported: Optional[List[str]] = None |
| 88 | + |
| 89 | + introspection_endpoint: Optional[str] = None |
| 90 | + """ |
| 91 | + URL of the authorization server's OAuth 2.0 introspection endpoint [[RFC7662](https://www.rfc-editor.org/rfc/rfc7662)]. |
| 92 | + """ |
| 93 | + |
| 94 | + introspection_endpoint_auth_methods_supported: Optional[List[str]] = None |
| 95 | + introspection_endpoint_auth_signing_alg_values_supported: Optional[List[str]] = None |
| 96 | + |
| 97 | + code_challenge_methods_supported: Optional[List[str]] = None |
| 98 | + """ |
| 99 | + JSON array containing a list of Proof Key for Code Exchange (PKCE) [[RFC7636](https://www.rfc-editor.org/rfc/rfc7636)] |
| 100 | + code challenge methods supported by this authorization server. |
| 101 | + """ |
| 102 | + |
| 103 | + |
| 104 | +class AuthServerType(str, Enum): |
| 105 | + """ |
| 106 | + The type of the authorization server. This information should be provided by the server |
| 107 | + configuration and indicates whether the server is an OAuth 2.0 or OpenID Connect (OIDC) |
| 108 | + authorization server. |
| 109 | + """ |
| 110 | + |
| 111 | + OAUTH = "oauth" |
| 112 | + OIDC = "oidc" |
| 113 | + |
| 114 | + |
| 115 | +class AuthServerConfig(BaseModel): |
| 116 | + """ |
| 117 | + Configuration for the remote authorization server integrated with the MCP server. |
| 118 | + """ |
| 119 | + |
| 120 | + metadata: AuthorizationServerMetadata |
| 121 | + """ |
| 122 | + The metadata of the authorization server, which should conform to the MCP specification |
| 123 | + (based on OAuth 2.0 Authorization Server Metadata). |
| 124 | +
|
| 125 | + This metadata is typically fetched from the server's well-known endpoint (OAuth 2.0 |
| 126 | + Authorization Server Metadata or OpenID Connect Discovery); it can also be provided |
| 127 | + directly in the configuration if the server does not support such endpoints. |
| 128 | +
|
| 129 | + See: |
| 130 | + - OAuth 2.0 Authorization Server Metadata: https://datatracker.ietf.org/doc/html/rfc8414 |
| 131 | + - OpenID Connect Discovery: https://openid.net/specs/openid-connect-discovery-1_0.html |
| 132 | + """ |
| 133 | + |
| 134 | + type: AuthServerType |
| 135 | + """ |
| 136 | + The type of the authorization server. See `AuthServerType` for possible values. |
| 137 | + """ |
| 138 | + |
| 139 | + |
| 140 | +class ServerMetadataPaths(str, Enum): |
| 141 | + """ |
| 142 | + Enum for server metadata paths. |
| 143 | + This is used to define the standard paths for OAuth and OIDC well-known URLs. |
| 144 | + """ |
| 145 | + |
| 146 | + OAUTH = "/.well-known/oauth-authorization-server" |
| 147 | + OIDC = "/.well-known/openid-configuration" |
0 commit comments