Skip to content

Commit b86e9ea

Browse files
committed
Make ResumeSession ResumeSessionAsync
- It calls IClientTransport.ConnectAsync, so it should be async as well
1 parent 6a20efe commit b86e9ea

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

src/ModelContextProtocol.Core/Client/HttpClientTransportOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public required Uri Endpoint
8484
/// </para>
8585
/// <para>
8686
/// Clients should pair this with
87-
/// <see cref="McpClient.ResumeSession(IClientTransport, ResumeClientSessionOptions, McpClientOptions?, Microsoft.Extensions.Logging.ILoggerFactory?, CancellationToken)"/>
87+
/// <see cref="McpClient.ResumeSessionAsync(IClientTransport, ResumeClientSessionOptions, McpClientOptions?, Microsoft.Extensions.Logging.ILoggerFactory?, CancellationToken)"/>
8888
/// to skip the initialization handshake when rehydrating a previously negotiated session.
8989
/// </para>
9090
/// </remarks>

src/ModelContextProtocol.Core/Client/McpClient.Methods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static async Task<McpClient> CreateAsync(
6060
/// <param name="cancellationToken">Token used when establishing the transport connection.</param>
6161
/// <returns>An <see cref="McpClient"/> bound to the resumed session.</returns>
6262
/// <exception cref="ArgumentNullException">Thrown when <paramref name="clientTransport"/> or <paramref name="resumeOptions"/> is <see langword="null"/>.</exception>
63-
public static McpClient ResumeSession(
63+
public static async Task<McpClient> ResumeSessionAsync(
6464
IClientTransport clientTransport,
6565
ResumeClientSessionOptions resumeOptions,
6666
McpClientOptions? clientOptions = null,
@@ -72,7 +72,7 @@ public static McpClient ResumeSession(
7272
Throw.IfNull(resumeOptions.ServerCapabilities);
7373
Throw.IfNull(resumeOptions.ServerInfo);
7474

75-
var transport = clientTransport.ConnectAsync(cancellationToken).GetAwaiter().GetResult();
75+
var transport = await clientTransport.ConnectAsync(cancellationToken).ConfigureAwait(false);
7676
var endpointName = clientTransport.Name;
7777

7878
var clientSession = new McpClientImpl(transport, endpointName, clientOptions, loggerFactory);

src/ModelContextProtocol.Core/Client/ResumeClientSessionOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public sealed class ResumeClientSessionOptions
1616
/// Gets or sets the server implementation metadata that identifies the connected MCP server.
1717
/// </summary>
1818
public required Implementation ServerInfo { get; set; }
19+
1920
/// <summary>
2021
/// Gets or sets any instructions previously supplied by the server.
2122
/// </summary>

src/ModelContextProtocol.Core/Client/StreamableHttpClientSessionTransport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal async Task<HttpResponseMessage> SendHttpRequestAsync(JsonRpcMessage mes
7171
{
7272
throw new InvalidOperationException(
7373
$"Cannot send '{RequestMethods.Initialize}' when {nameof(HttpClientTransportOptions)}.{nameof(HttpClientTransportOptions.KnownSessionId)} is configured. " +
74-
$"Call {nameof(McpClient)}.{nameof(McpClient.ResumeSession)} to resume existing sessions.");
74+
$"Call {nameof(McpClient)}.{nameof(McpClient.ResumeSessionAsync)} to resume existing sessions.");
7575
}
7676

7777
using var sendCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _connectionCts.Token);

tests/ModelContextProtocol.AspNetCore.Tests/MapMcpStreamableHttpTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public async Task CanResumeSessionWithMapMcpAndRunSessionHandler()
268268
NegotiatedProtocolVersion = negotiatedProtocolVersion,
269269
};
270270

271-
await using (var resumedClient = McpClient.ResumeSession(
271+
await using (var resumedClient = await McpClient.ResumeSessionAsync(
272272
resumeTransport,
273273
resumeOptions,
274274
loggerFactory: LoggerFactory,

tests/ModelContextProtocol.AspNetCore.Tests/StreamableHttpClientConformanceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public async Task ResumeSessionStartsGetImmediately()
239239
NegotiatedProtocolVersion = resumeProtocolVersion,
240240
};
241241

242-
await using (var client = McpClient.ResumeSession(
242+
await using (var client = await McpClient.ResumeSessionAsync(
243243
transport,
244244
resumeOptions,
245245
loggerFactory: LoggerFactory,
@@ -277,7 +277,7 @@ public async Task CreateAsyncWithKnownSessionIdThrows()
277277
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() =>
278278
McpClient.CreateAsync(transport, loggerFactory: LoggerFactory, cancellationToken: TestContext.Current.CancellationToken));
279279

280-
Assert.Contains(nameof(McpClient.ResumeSession), exception.Message);
280+
Assert.Contains(nameof(McpClient.ResumeSessionAsync), exception.Message);
281281
}
282282

283283
private static async Task CallEchoAndValidateAsync(McpClientTool echoTool)

0 commit comments

Comments
 (0)