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