Skip to content

Commit 71a2c97

Browse files
Copilotstephentoub
andauthored
Use IPAddress.IsLoopback for robust IPv6 loopback detection and fix docs
Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/8a200407-8cc6-4c69-97e0-c9a6ad509b93 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 57a9888 commit 71a2c97

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,7 @@ private async Task PerformDynamicClientRegistrationAsync(
717717

718718
private static bool IsLocalhostRedirectUri(Uri redirectUri)
719719
=> redirectUri.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)
720-
|| redirectUri.Host.Equals("127.0.0.1", StringComparison.Ordinal)
721-
|| redirectUri.Host.Equals("::1", StringComparison.Ordinal);
720+
|| (System.Net.IPAddress.TryParse(redirectUri.Host, out var ipAddress) && System.Net.IPAddress.IsLoopback(ipAddress));
722721

723722
private string? GetScopeParameter(ProtectedResourceMetadata protectedResourceMetadata)
724723
{

src/ModelContextProtocol.Core/Authentication/DynamicClientRegistrationRequest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ internal sealed class DynamicClientRegistrationRequest
5353
/// Gets or sets the application type for the client, as defined in OpenID Connect Dynamic Client Registration 1.0.
5454
/// </summary>
5555
/// <remarks>
56-
/// Valid values are "native" and "web". MCP clients MUST specify this during Dynamic Client Registration.
56+
/// Valid values are "native" and "web". Per the MCP specification, MCP clients MUST specify an appropriate
57+
/// application type during Dynamic Client Registration. This field is automatically populated by the SDK
58+
/// based on the redirect URI if not explicitly set via <see cref="DynamicClientRegistrationOptions.ApplicationType"/>.
5759
/// Native applications (desktop, mobile, CLI, localhost web apps) should use "native".
5860
/// Web applications (remote browser-based) should use "web".
5961
/// </remarks>

0 commit comments

Comments
 (0)