Skip to content

Commit 84b5585

Browse files
Copilotmikekistler
andauthored
Sort accumulated scopes for deterministic output in GetScopeParameter
Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/4331950d-e33b-4bdd-b88a-eb6c8f0f6988 Co-authored-by: mikekistler <85643503+mikekistler@users.noreply.github.com>
1 parent 97ba119 commit 84b5585

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ private async Task PerformDynamicClientRegistrationAsync(
737737
{
738738
// If we have previously requested scopes but nothing new, return the accumulated set.
739739
return _previouslyRequestedScopes.Count > 0
740-
? string.Join(" ", _previouslyRequestedScopes)
740+
? string.Join(" ", _previouslyRequestedScopes.OrderBy(s => s, StringComparer.Ordinal))
741741
: null;
742742
}
743743
}
@@ -752,7 +752,8 @@ private async Task PerformDynamicClientRegistrationAsync(
752752
_previouslyRequestedScopes.Add(scope);
753753
}
754754

755-
return string.Join(" ", _previouslyRequestedScopes);
755+
// Sort scopes for stable, deterministic output (scopes are unordered per RFC 6749 §3.3).
756+
return string.Join(" ", _previouslyRequestedScopes.OrderBy(s => s, StringComparer.Ordinal));
756757
}
757758
}
758759

tests/ModelContextProtocol.AspNetCore.Tests/OAuth/AuthTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ public async Task AuthorizationFlow_UsesScopeFromProtectedResourceMetadata()
409409
await using var client = await McpClient.CreateAsync(
410410
transport, loggerFactory: LoggerFactory, cancellationToken: TestContext.Current.CancellationToken);
411411

412-
Assert.Equal("mcp:tools files:read", requestedScope);
412+
var requestedScopeSet = new HashSet<string>(requestedScope!.Split(' '));
413+
Assert.Contains("mcp:tools", requestedScopeSet);
414+
Assert.Contains("files:read", requestedScopeSet);
413415
}
414416

415417
[Fact]

0 commit comments

Comments
 (0)