diff --git a/src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs b/src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs index 75126556b..312814784 100644 --- a/src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs +++ b/src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs @@ -24,6 +24,7 @@ internal sealed partial class ClientOAuthProvider : McpHttpClient /// private const string BearerScheme = "Bearer"; private const string ProtectedResourceMetadataWellKnownPath = "/.well-known/oauth-protected-resource"; + private static readonly string HttpsPlusHttpScheme = $"{Uri.UriSchemeHttps}+{Uri.UriSchemeHttp}"; private readonly Uri _serverUrl; private readonly Uri _redirectUri; @@ -342,10 +343,13 @@ private async Task GetAuthServerMetadataAsync(Uri a ThrowFailedToHandleUnauthorizedResponse($"No authorization_endpoint was provided via '{wellKnownEndpoint}'."); } - if (metadata.AuthorizationEndpoint.Scheme != Uri.UriSchemeHttp && - metadata.AuthorizationEndpoint.Scheme != Uri.UriSchemeHttps) + string authorizationEndpointScheme = metadata.AuthorizationEndpoint.Scheme; + + if (authorizationEndpointScheme != Uri.UriSchemeHttp && + authorizationEndpointScheme != Uri.UriSchemeHttps && + authorizationEndpointScheme != HttpsPlusHttpScheme) { - ThrowFailedToHandleUnauthorizedResponse($"AuthorizationEndpoint must use HTTP or HTTPS. '{metadata.AuthorizationEndpoint}' does not meet this requirement."); + ThrowFailedToHandleUnauthorizedResponse($"AuthorizationEndpoint must use HTTP, HTTPS, or HTTPS+HTTP. '{metadata.AuthorizationEndpoint}' does not meet this requirement."); } metadata.ResponseTypesSupported ??= ["code"]; diff --git a/src/ModelContextProtocol.Core/Client/HttpClientTransportOptions.cs b/src/ModelContextProtocol.Core/Client/HttpClientTransportOptions.cs index 73eaae700..2168310a5 100644 --- a/src/ModelContextProtocol.Core/Client/HttpClientTransportOptions.cs +++ b/src/ModelContextProtocol.Core/Client/HttpClientTransportOptions.cs @@ -7,6 +7,8 @@ namespace ModelContextProtocol.Client; /// public sealed class HttpClientTransportOptions { + private static readonly string HttpsPlusHttpScheme = $"{Uri.UriSchemeHttps}+{Uri.UriSchemeHttp}"; + /// /// Gets or sets the base address of the server for SSE connections. /// @@ -25,9 +27,13 @@ public required Uri Endpoint { throw new ArgumentException("Endpoint must be an absolute URI.", nameof(value)); } - if (value.Scheme != Uri.UriSchemeHttp && value.Scheme != Uri.UriSchemeHttps) + string scheme = value.Scheme; + + if (scheme != Uri.UriSchemeHttp && + scheme != Uri.UriSchemeHttps && + scheme != HttpsPlusHttpScheme) { - throw new ArgumentException("Endpoint must use HTTP or HTTPS scheme.", nameof(value)); + throw new ArgumentException("Endpoint must use HTTP, HTTPS, or HTTPS+HTTP scheme.", nameof(value)); } field = value;