Skip to content

Commit b519e7a

Browse files
committed
Address PR feedback
1 parent b87bb40 commit b519e7a

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/ModelContextProtocol/Logging/Log.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ internal static partial class Log
6868
[LoggerMessage(Level = LogLevel.Error, Message = "Request failed for {endpointName} with method {method}: {message} ({code})")]
6969
internal static partial void RequestFailed(this ILogger logger, string endpointName, string method, string message, int code);
7070

71+
[LoggerMessage(Level = LogLevel.Information, Message = "Request '{requestId}' canceled via client notification.")]
72+
internal static partial void RequestCanceled(this ILogger logger, RequestId requestId);
73+
7174
[LoggerMessage(Level = LogLevel.Information, Message = "Request response received payload for {endpointName}: {payload}")]
7275
internal static partial void RequestResponseReceivedPayload(this ILogger logger, string endpointName, string payload);
7376

src/ModelContextProtocol/Shared/McpSession.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ namespace ModelContextProtocol.Shared;
1616
/// </summary>
1717
internal sealed class McpSession : IDisposable
1818
{
19-
/// <summary>
20-
/// In-flight request handling, indexed by request ID. The value provides a <see cref="CancellationTokenSource"/>
21-
/// that can be used to request cancellation of the in-flight handler.
22-
/// </summary>
23-
private static readonly ConcurrentDictionary<RequestId, CancellationTokenSource> s_handlingRequests = new();
24-
2519
private readonly ITransport _transport;
2620
private readonly RequestHandlers _requestHandlers;
2721
private readonly NotificationHandlers _notificationHandlers;
2822

23+
/// <summary>Collection of requests sent on this session and waiting for responses.</summary>
2924
private readonly ConcurrentDictionary<RequestId, TaskCompletionSource<IJsonRpcMessage>> _pendingRequests = [];
25+
/// <summary>
26+
/// Collection of requests received on this session and currently being handled. The value provides a <see cref="CancellationTokenSource"/>
27+
/// that can be used to request cancellation of the in-flight handler.
28+
/// </summary>
29+
private readonly ConcurrentDictionary<RequestId, CancellationTokenSource> s_handlingRequests = new();
3030
private readonly JsonSerializerOptions _jsonOptions;
3131
private readonly ILogger _logger;
3232

@@ -183,6 +183,7 @@ private async Task HandleNotification(JsonRpcNotification notification)
183183
s_handlingRequests.TryGetValue(cn.RequestId, out var cts))
184184
{
185185
await cts.CancelAsync().ConfigureAwait(false);
186+
_logger.RequestCanceled(cn.RequestId);
186187
}
187188
}
188189
catch

0 commit comments

Comments
 (0)