@@ -145,13 +145,9 @@ public override async ValueTask DisposeAsync()
145145 try
146146 {
147147 // Send DELETE request to terminate the session only send if we have a session ID per MCP spec
148- if ( ! string . IsNullOrEmpty ( _mcpSessionId ) )
148+ if ( ! string . IsNullOrEmpty ( SessionId ) )
149149 {
150- using var deleteRequest = new HttpRequestMessage ( HttpMethod . Delete , _options . Endpoint ) ;
151- CopyAdditionalHeaders ( deleteRequest . Headers , _options . AdditionalHeaders , _mcpSessionId ) ;
152-
153- // Do not validate we get a successful status code, because server support for the DELETE request is optional
154- using var deleteResponse = await _httpClient . SendAsync ( deleteRequest , CancellationToken . None ) . ConfigureAwait ( false ) ;
150+ await SendDeleteRequest ( ) ;
155151 }
156152
157153 if ( _getReceiveTask != null )
@@ -246,6 +242,22 @@ message is JsonRpcMessageWithId rpcResponseOrError &&
246242 return null ;
247243 }
248244
245+ private async Task SendDeleteRequest ( )
246+ {
247+ using var deleteRequest = new HttpRequestMessage ( HttpMethod . Delete , _options . Endpoint ) ;
248+ CopyAdditionalHeaders ( deleteRequest . Headers , _options . AdditionalHeaders , SessionId , _negotiatedProtocolVersion ) ;
249+
250+ try
251+ {
252+ // Do not validate we get a successful status code, because server support for the DELETE request is optional
253+ ( await _httpClient . SendAsync ( deleteRequest , CancellationToken . None ) . ConfigureAwait ( false ) ) . Dispose ( ) ;
254+ }
255+ catch ( Exception ex )
256+ {
257+ LogTransportShutdownFailed ( Name , ex ) ;
258+ }
259+ }
260+
249261 private void LogJsonException ( JsonException ex , string data )
250262 {
251263 if ( _logger . IsEnabled ( LogLevel . Trace ) )
@@ -261,8 +273,8 @@ private void LogJsonException(JsonException ex, string data)
261273 internal static void CopyAdditionalHeaders (
262274 HttpRequestHeaders headers ,
263275 IDictionary < string , string > ? additionalHeaders ,
264- string ? sessionId = null ,
265- string ? protocolVersion = null )
276+ string ? sessionId ,
277+ string ? protocolVersion )
266278 {
267279 if ( sessionId is not null )
268280 {
0 commit comments