Skip to content

Commit bfc0980

Browse files
authored
Add net10.0 assets and run some fixers (#875)
1 parent e7b403b commit bfc0980

File tree

46 files changed

+168
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+168
-194
lines changed

Directory.Packages.props

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project>
22
<PropertyGroup>
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
<System9Version>9.0.5</System9Version>
5-
<System10Version>10.0.0-preview.4.25258.110</System10Version>
6-
<MicrosoftExtensionsAIVersion>9.9.1</MicrosoftExtensionsAIVersion>
4+
<System9Version>9.0.10</System9Version>
5+
<System10Version>10.0.0-rc.2.25502.107</System10Version>
6+
<MicrosoftExtensionsAIVersion>9.10.0</MicrosoftExtensionsAIVersion>
77
</PropertyGroup>
88

99
<!-- Product dependencies netstandard -->
@@ -28,19 +28,17 @@
2828
<!-- Product dependencies .NET 9 -->
2929
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
3030
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(System9Version)" />
31-
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.9.0" />
31+
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
3232
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(System9Version)" />
3333
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(System9Version)" />
34-
<PackageVersion Include="System.IO.Pipelines" Version="$(System9Version)" />
3534
</ItemGroup>
3635

3736
<!-- Product dependencies .NET 10 -->
3837
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
3938
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(System10Version)" />
40-
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.9.0" />
39+
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
4140
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(System10Version)" />
4241
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(System10Version)" />
43-
<PackageVersion Include="System.IO.Pipelines" Version="$(System10Version)" />
4442
</ItemGroup>
4543

4644
<!-- Product dependencies shared -->
@@ -56,19 +54,19 @@
5654
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
5755

5856
<!-- Testing dependencies -->
59-
<PackageVersion Include="Anthropic.SDK" Version="5.5.1" />
57+
<PackageVersion Include="Anthropic.SDK" Version="5.6.0" />
6058
<PackageVersion Include="coverlet.collector" Version="6.0.4">
6159
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6260
<PrivateAssets>all</PrivateAssets>
6361
</PackageVersion>
6462
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
65-
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.9.1-preview.1.25474.6" />
63+
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.0-preview.1.25513.3" />
6664
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(System9Version)" />
6765
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(System9Version)" />
6866
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(System9Version)" />
6967
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="$(System9Version)" />
7068
<PackageVersion Include="Microsoft.Extensions.Options" Version="$(System9Version)" />
71-
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.5.0" />
69+
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.10.0" />
7270
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
7371
<PackageVersion Include="Moq" Version="4.20.72" />
7472
<PackageVersion Include="OpenTelemetry" Version="1.12.0" />

docs/concepts/elicitation/samples/server/Tools/InteractiveTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ CancellationToken token
7373
string? playerName = nameResponse.Content?["Name"].GetString();
7474

7575
// Generate a random number between 1 and 10
76-
Random random = new Random();
76+
Random random = new();
7777
int targetNumber = random.Next(1, 11); // 1 to 10 inclusive
7878
int attempts = 0;
7979

samples/AspNetCoreMcpPerSessionTools/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{
2525
mcpOptions.Capabilities = new();
2626
mcpOptions.Capabilities.Tools = new();
27-
var toolCollection = mcpOptions.ToolCollection = new();
27+
var toolCollection = mcpOptions.ToolCollection = [];
2828

2929
foreach (var tool in tools)
3030
{

src/Common/CancellableStreamReader/CancellableStreamReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public override string ReadToEnd()
350350
CheckAsyncTaskInProgress();
351351

352352
// Call ReadBuffer, then pull data out of charBuffer.
353-
StringBuilder sb = new StringBuilder(_charLen - _charPos);
353+
StringBuilder sb = new(_charLen - _charPos);
354354
do
355355
{
356356
sb.Append(_charBuffer, _charPos, _charLen - _charPos);
@@ -953,7 +953,7 @@ public virtual Task<string> ReadToEndAsync(CancellationToken cancellationToken)
953953
private async Task<string> ReadToEndAsyncInternal(CancellationToken cancellationToken)
954954
{
955955
// Call ReadBuffer, then pull data out of charBuffer.
956-
StringBuilder sb = new StringBuilder(_charLen - _charPos);
956+
StringBuilder sb = new(_charLen - _charPos);
957957
do
958958
{
959959
int tmpCharPos = _charPos;

src/ModelContextProtocol.AspNetCore/Authentication/McpAuthenticationOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public McpAuthenticationOptions()
2525
/// Gets or sets the events used to handle authentication events.
2626
/// </summary>
2727
public new McpAuthenticationEvents Events
28-
{
29-
get { return (McpAuthenticationEvents)base.Events!; }
30-
set { base.Events = value; }
28+
{
29+
get => (McpAuthenticationEvents)base.Events!;
30+
set => base.Events = value;
3131
}
3232

3333
/// <summary>

src/ModelContextProtocol.AspNetCore/AuthorizationFilterSetup.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ await FilterAuthorizedItemsAsync(
5555
});
5656
}
5757

58-
private void CheckListToolsFilter(McpServerOptions options)
58+
private static void CheckListToolsFilter(McpServerOptions options)
5959
{
6060
options.Filters.ListToolsFilters.Add(next => async (context, cancellationToken) =>
6161
{
@@ -87,7 +87,7 @@ private void ConfigureCallToolFilter(McpServerOptions options)
8787
});
8888
}
8989

90-
private void CheckCallToolFilter(McpServerOptions options)
90+
private static void CheckCallToolFilter(McpServerOptions options)
9191
{
9292
options.Filters.CallToolFilters.Add(next => async (context, cancellationToken) =>
9393
{
@@ -115,7 +115,7 @@ await FilterAuthorizedItemsAsync(
115115
});
116116
}
117117

118-
private void CheckListResourcesFilter(McpServerOptions options)
118+
private static void CheckListResourcesFilter(McpServerOptions options)
119119
{
120120
options.Filters.ListResourcesFilters.Add(next => async (context, cancellationToken) =>
121121
{
@@ -145,7 +145,7 @@ await FilterAuthorizedItemsAsync(
145145
});
146146
}
147147

148-
private void CheckListResourceTemplatesFilter(McpServerOptions options)
148+
private static void CheckListResourceTemplatesFilter(McpServerOptions options)
149149
{
150150
options.Filters.ListResourceTemplatesFilters.Add(next => async (context, cancellationToken) =>
151151
{
@@ -177,7 +177,7 @@ private void ConfigureReadResourceFilter(McpServerOptions options)
177177
});
178178
}
179179

180-
private void CheckReadResourceFilter(McpServerOptions options)
180+
private static void CheckReadResourceFilter(McpServerOptions options)
181181
{
182182
options.Filters.ReadResourceFilters.Add(next => async (context, cancellationToken) =>
183183
{
@@ -205,7 +205,7 @@ await FilterAuthorizedItemsAsync(
205205
});
206206
}
207207

208-
private void CheckListPromptsFilter(McpServerOptions options)
208+
private static void CheckListPromptsFilter(McpServerOptions options)
209209
{
210210
options.Filters.ListPromptsFilters.Add(next => async (context, cancellationToken) =>
211211
{
@@ -237,7 +237,7 @@ private void ConfigureGetPromptFilter(McpServerOptions options)
237237
});
238238
}
239239

240-
private void CheckGetPromptFilter(McpServerOptions options)
240+
private static void CheckGetPromptFilter(McpServerOptions options)
241241
{
242242
options.Filters.GetPromptFilters.Add(next => async (context, cancellationToken) =>
243243
{

src/ModelContextProtocol.AspNetCore/ModelContextProtocol.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>

src/ModelContextProtocol.Core/AIContentExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ public static IList<PromptMessage> ToPromptMessages(this ChatMessage chatMessage
128128
_ => null,
129129
};
130130

131-
if (ac is not null)
132-
{
133-
ac.RawRepresentation = content;
134-
}
131+
ac?.RawRepresentation = content;
135132

136133
return ac;
137134
}

src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using Microsoft.Extensions.Logging;
22
using Microsoft.Extensions.Logging.Abstractions;
3+
#if NET9_0_OR_GREATER
4+
using System.Buffers.Text;
5+
#endif
36
using System.Diagnostics.CodeAnalysis;
47
using System.Net.Http.Headers;
58
using System.Security.Cryptography;
@@ -238,14 +241,17 @@ private async Task PerformOAuthAuthorizationAsync(
238241
LogOAuthAuthorizationCompleted();
239242
}
240243

244+
private static readonly string[] s_wellKnownPaths = [".well-known/openid-configuration", ".well-known/oauth-authorization-server"];
245+
241246
private async Task<AuthorizationServerMetadata> GetAuthServerMetadataAsync(Uri authServerUri, CancellationToken cancellationToken)
242247
{
243-
if (!authServerUri.OriginalString.EndsWith("/"))
248+
if (authServerUri.OriginalString.Length == 0 ||
249+
authServerUri.OriginalString[authServerUri.OriginalString.Length - 1] != '/')
244250
{
245-
authServerUri = new Uri(authServerUri.OriginalString + "/");
251+
authServerUri = new Uri($"{authServerUri.OriginalString}/");
246252
}
247253

248-
foreach (var path in new[] { ".well-known/openid-configuration", ".well-known/oauth-authorization-server" })
254+
foreach (var path in s_wellKnownPaths)
249255
{
250256
try
251257
{
@@ -540,11 +546,7 @@ private static string NormalizeUri(Uri uri)
540546
Port = -1 // Always remove port
541547
};
542548

543-
if (builder.Path == "/")
544-
{
545-
builder.Path = string.Empty;
546-
}
547-
else if (builder.Path.Length > 1 && builder.Path.EndsWith("/"))
549+
if (builder.Path.Length > 0 && builder.Path[builder.Path.Length - 1] == '/')
548550
{
549551
builder.Path = builder.Path.TrimEnd('/');
550552
}
@@ -633,18 +635,18 @@ private async Task<ProtectedResourceMetadata> ExtractProtectedResourceMetadata(H
633635
continue;
634636
}
635637

636-
string key = trimmedPart.Substring(0, equalsIndex).Trim();
638+
ReadOnlySpan<char> key = trimmedPart.AsSpan().Slice(0, equalsIndex).Trim();
637639

638-
if (string.Equals(key, parameterName, StringComparison.OrdinalIgnoreCase))
640+
if (key.Equals(parameterName, StringComparison.OrdinalIgnoreCase))
639641
{
640-
string value = trimmedPart.Substring(equalsIndex + 1).Trim();
642+
ReadOnlySpan<char> value = trimmedPart.AsSpan(equalsIndex + 1).Trim();
641643

642-
if (value.StartsWith("\"") && value.EndsWith("\""))
644+
if (value.Length > 0 && value[0] == '"' && value[value.Length - 1] == '"')
643645
{
644-
value = value.Substring(1, value.Length - 2);
646+
value = value.Slice(1, value.Length - 2);
645647
}
646648

647-
return value;
649+
return value.ToString();
648650
}
649651
}
650652

@@ -664,12 +666,18 @@ private static string GenerateCodeVerifier()
664666

665667
private static string GenerateCodeChallenge(string codeVerifier)
666668
{
669+
#if NET9_0_OR_GREATER
670+
Span<byte> hash = stackalloc byte[SHA256.HashSizeInBytes];
671+
SHA256.HashData(Encoding.UTF8.GetBytes(codeVerifier), hash);
672+
return Base64Url.EncodeToString(hash);
673+
#else
667674
using var sha256 = SHA256.Create();
668675
var challengeBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(codeVerifier));
669676
return Convert.ToBase64String(challengeBytes)
670677
.TrimEnd('=')
671678
.Replace('+', '-')
672679
.Replace('/', '_');
680+
#endif
673681
}
674682

675683
private string GetClientIdOrThrow() => _clientId ?? throw new InvalidOperationException("Client ID is not available. This may indicate an issue with dynamic client registration.");

src/ModelContextProtocol.Core/Client/McpClientOptions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace ModelContextProtocol.Client;
1111
/// </remarks>
1212
public sealed class McpClientOptions
1313
{
14-
private McpClientHandlers? _handlers;
15-
1614
/// <summary>
1715
/// Gets or sets information about this client implementation, including its name and version.
1816
/// </summary>
@@ -71,11 +69,11 @@ public sealed class McpClientOptions
7169
/// </summary>
7270
public McpClientHandlers Handlers
7371
{
74-
get => _handlers ??= new();
72+
get => field ??= new();
7573
set
7674
{
7775
Throw.IfNull(value);
78-
_handlers = value;
76+
field = value;
7977
}
8078
}
8179
}

0 commit comments

Comments
 (0)