Change handlers to support cancellation token (#99)

* wire the cancellation

* missed file
This commit is contained in:
Diego Colombo 2025-03-18 15:36:22 +00:00 • committed by GitHub
commit c0e1d0dd9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,13 +1,15 @@
using System.Text.Json;
using McpDotNet.Configuration;
using McpDotNet.Configuration;
using McpDotNet.Logging;
using McpDotNet.Protocol.Messages;
using McpDotNet.Protocol.Transport;
using McpDotNet.Protocol.Types;
using McpDotNet.Shared;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System.Text.Json;
namespace McpDotNet.Client;
/// <inheritdoc/>
@ -16,7 +18,7 @@ internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
private readonly McpClientOptions _options;
private readonly ILogger _logger;
private readonly IClientTransport _clientTransport;
private volatile bool _isInitializing;
/// <summary>
@ -44,7 +46,7 @@ internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
SetRequestHandler<CreateMessageRequestParams, CreateMessageResult>(
"sampling/createMessage",
request => samplingHandler(request, CancellationTokenSource?.Token ?? default));
(request, ct) => samplingHandler(request, ct));
}
if (options.Capabilities?.Roots is { } rootsCapability)
@ -56,7 +58,7 @@ internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
SetRequestHandler<ListRootsRequestParams, ListRootsResult>(
"roots/list",
request => rootsHandler(request, CancellationTokenSource?.Token ?? default));
(request, ct) => rootsHandler(request, ct));
}
}