Skip to content

Commit 5bf5a63

Browse files
committed
Address PR feedback
1 parent 29e6f9f commit 5bf5a63

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/ModelContextProtocol.Core/Client/StreamableHttpClientSessionTransport.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ internal async Task<HttpResponseMessage> SendHttpRequestAsync(JsonRpcMessage mes
100100
// indicates the session has ended. Signal completion so McpClient.Completion resolves.
101101
if (response.StatusCode == HttpStatusCode.NotFound && SessionId is not null)
102102
{
103-
SetSessionExpired(response.StatusCode);
103+
SetSessionExpired();
104104
}
105105

106106
return response;
@@ -198,6 +198,8 @@ public override async ValueTask DisposeAsync()
198198
// This class isn't directly exposed to public callers, so we don't have to worry about changing the _state in this case.
199199
if (_options.TransportMode is not HttpTransportMode.AutoDetect || _getReceiveTask is not null)
200200
{
201+
// _disconnectError is set when the server returns 404 indicating session expiry.
202+
// When null, this is a graceful client-initiated closure (no error).
201203
SetDisconnected(_disconnectError ?? new TransportClosedException(new HttpClientCompletionDetails()));
202204
}
203205
}
@@ -292,7 +294,7 @@ await SendGetSseRequestWithRetriesAsync(
292294
// indicates the session has ended. Signal completion so McpClient.Completion resolves.
293295
if (response.StatusCode == HttpStatusCode.NotFound && SessionId is not null)
294296
{
295-
SetSessionExpired(response.StatusCode);
297+
SetSessionExpired();
296298
}
297299

298300
// If the server could be reached but returned a non-success status code,
@@ -485,13 +487,13 @@ private static TimeSpan ElapsedSince(long stopwatchTimestamp)
485487
#endif
486488
}
487489

488-
private void SetSessionExpired(HttpStatusCode statusCode)
490+
private void SetSessionExpired()
489491
{
490492
// Store the error before canceling so DisposeAsync can use it if it races us, especially
491493
// after the call to Cancel below, to invoke SetDisconnected.
492494
_disconnectError = new TransportClosedException(new HttpClientCompletionDetails
493495
{
494-
HttpStatusCode = statusCode,
496+
HttpStatusCode = HttpStatusCode.NotFound,
495497
Exception = new McpException(
496498
"The server returned HTTP 404 for a request with an Mcp-Session-Id, indicating the session has expired. " +
497499
"To continue, create a new client session or call ResumeSessionAsync with a new connection."),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
3+
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
4+
<!-- McpClient's constructor is marked [Experimental], so adding abstract members is acceptable. -->
5+
<Suppression>
6+
<DiagnosticId>CP0005</DiagnosticId>
7+
<Target>M:ModelContextProtocol.Client.McpClient.get_Completion</Target>
8+
<Left>lib/netstandard2.0/ModelContextProtocol.Core.dll</Left>
9+
<Right>lib/netstandard2.0/ModelContextProtocol.Core.dll</Right>
10+
</Suppression>
11+
<Suppression>
12+
<DiagnosticId>CP0005</DiagnosticId>
13+
<Target>M:ModelContextProtocol.Client.McpClient.get_Completion</Target>
14+
<Left>lib/net8.0/ModelContextProtocol.Core.dll</Left>
15+
<Right>lib/net8.0/ModelContextProtocol.Core.dll</Right>
16+
</Suppression>
17+
<Suppression>
18+
<DiagnosticId>CP0005</DiagnosticId>
19+
<Target>M:ModelContextProtocol.Client.McpClient.get_Completion</Target>
20+
<Left>lib/net9.0/ModelContextProtocol.Core.dll</Left>
21+
<Right>lib/net9.0/ModelContextProtocol.Core.dll</Right>
22+
</Suppression>
23+
<Suppression>
24+
<DiagnosticId>CP0005</DiagnosticId>
25+
<Target>M:ModelContextProtocol.Client.McpClient.get_Completion</Target>
26+
<Left>lib/net10.0/ModelContextProtocol.Core.dll</Left>
27+
<Right>lib/net10.0/ModelContextProtocol.Core.dll</Right>
28+
</Suppression>
29+
</Suppressions>

0 commit comments

Comments
 (0)