@@ -53,7 +53,7 @@ public async Task AutoDetectMode_UsesStreamableHttp_WhenServerSupportsIt()
5353 [ Fact ]
5454 public async Task AutoDetectMode_WhenBothTransportsFail_PreservesStreamableHttpException ( )
5555 {
56- // Regression test: when Streamable HTTP POST fails (e.g. 403 ) and the SSE GET
56+ // Regression test: when Streamable HTTP POST fails (e.g. 404 ) and the SSE GET
5757 // fallback also fails (e.g. 405), the original Streamable HTTP error should
5858 // be preserved. The SSE connection failure is available as its inner exception.
5959 var options = new HttpClientTransportOptions
@@ -71,11 +71,11 @@ public async Task AutoDetectMode_WhenBothTransportsFail_PreservesStreamableHttpE
7171 {
7272 if ( request . Method == HttpMethod . Post )
7373 {
74- // Streamable HTTP POST fails with 403 (auth error)
74+ // Streamable HTTP POST fails with 404 (an SSE-only server with no POST endpoint).
7575 return Task . FromResult ( new HttpResponseMessage
7676 {
77- StatusCode = HttpStatusCode . Forbidden ,
78- Content = new StringContent ( "Forbidden " )
77+ StatusCode = HttpStatusCode . NotFound ,
78+ Content = new StringContent ( "Streamable HTTP not supported " )
7979 } ) ;
8080 }
8181
@@ -99,12 +99,12 @@ public async Task AutoDetectMode_WhenBothTransportsFail_PreservesStreamableHttpE
9999 var ex = await Assert . ThrowsAsync < HttpRequestException > (
100100 ( ) => McpClient . CreateAsync ( transport , cancellationToken : TestContext . Current . CancellationToken ) ) ;
101101
102- Assert . Contains ( "403 " , ex . Message ) ;
102+ Assert . Contains ( "404 " , ex . Message ) ;
103103 Assert . IsType < HttpRequestException > ( ex . InnerException ) ;
104104 Assert . Contains ( "405" , ex . InnerException . Message ) ;
105- Assert . Equal ( HttpStatusCode . Forbidden , ex . Data [ "ModelContextProtocol.HttpStatusCode" ] ) ;
105+ Assert . Equal ( HttpStatusCode . NotFound , ex . Data [ "ModelContextProtocol.HttpStatusCode" ] ) ;
106106#if NET
107- Assert . Equal ( HttpStatusCode . Forbidden , ex . StatusCode ) ;
107+ Assert . Equal ( HttpStatusCode . NotFound , ex . StatusCode ) ;
108108#endif
109109 }
110110
@@ -278,11 +278,12 @@ await session.SendMessageAsync(
278278 }
279279
280280 // Regression test for https://github.com/modelcontextprotocol/csharp-sdk/issues/1526
281- // When Streamable HTTP returns 415 (e.g. wrong Content-Type) and the SSE fallback also fails
282- // (e.g. a Streamable-HTTP-only server returns 405 to the GET), the surfaced exception must
283- // preserve the original Streamable HTTP error rather than dropping it on the floor.
281+ // When Streamable HTTP returns 404 (e.g. an SSE-only server with no POST endpoint) and the
282+ // SSE fallback also fails (e.g. a Streamable-HTTP-only server returns 405 to the GET), the
283+ // surfaced exception must preserve the original Streamable HTTP error rather than dropping
284+ // it on the floor.
284285 [ Fact ]
285- public async Task AutoDetectMode_PreservesOriginalError_WhenStreamableHttpReturns415AndSseFallbackFails ( )
286+ public async Task AutoDetectMode_PreservesOriginalError_WhenStreamableHttpReturns404AndSseFallbackFails ( )
286287 {
287288 var options = new HttpClientTransportOptions
288289 {
@@ -295,24 +296,24 @@ public async Task AutoDetectMode_PreservesOriginalError_WhenStreamableHttpReturn
295296 using var httpClient = new HttpClient ( mockHttpHandler ) ;
296297 await using var transport = new HttpClientTransport ( options , httpClient , LoggerFactory ) ;
297298
298- const string streamableHttpBody = "Content-Type must be 'application/json' " ;
299+ const string streamableHttpBody = "Streamable HTTP not supported " ;
299300
300301 mockHttpHandler . RequestHandler = ( request ) =>
301302 {
302303 if ( request . Method == HttpMethod . Post )
303304 {
304- // Streamable HTTP fails with 415 - this is the real server diagnostic the user needs to see.
305+ // Streamable HTTP fails with 404 - this is the real server diagnostic the user needs to see.
305306 return Task . FromResult ( new HttpResponseMessage
306307 {
307- StatusCode = HttpStatusCode . UnsupportedMediaType ,
308+ StatusCode = HttpStatusCode . NotFound ,
308309 Content = new StringContent ( streamableHttpBody ) ,
309310 } ) ;
310311 }
311312
312313 if ( request . Method == HttpMethod . Get )
313314 {
314315 // Streamable-HTTP-only server: SSE GET is rejected with 405. Without the fix this is the
315- // ONLY error the user ever sees, masking the real 415 diagnostic above.
316+ // ONLY error the user ever sees, masking the real 404 diagnostic above.
316317 return Task . FromResult ( new HttpResponseMessage
317318 {
318319 StatusCode = HttpStatusCode . MethodNotAllowed ,
@@ -331,11 +332,11 @@ public async Task AutoDetectMode_PreservesOriginalError_WhenStreamableHttpReturn
331332 new JsonRpcRequest { Method = RequestMethods . Initialize , Id = new RequestId ( 1 ) } ,
332333 TestContext . Current . CancellationToken ) ) ;
333334
334- // Walk the exception chain and assert the original 415 (and its body) is somewhere in it.
335+ // Walk the exception chain and assert the original 404 (and its body) is somewhere in it.
335336 // We don't pin the exact exception type so this stays robust to future error-shape tweaks,
336337 // but the underlying status code and server body must reach the caller.
337338 var combined = Flatten ( ex ) ;
338- Assert . Contains ( "415 " , combined ) ;
339+ Assert . Contains ( "404 " , combined ) ;
339340 Assert . Contains ( streamableHttpBody , combined ) ;
340341
341342 static string Flatten ( Exception e )
@@ -378,15 +379,15 @@ public async Task AutoDetectMode_SurfacesStreamableHttpError_WithSseAsInner_When
378379 using var httpClient = new HttpClient ( mockHttpHandler ) ;
379380 await using var transport = new HttpClientTransport ( options , httpClient , LoggerFactory ) ;
380381
381- const string streamableHttpBody = "Content-Type must be 'application/json' " ;
382+ const string streamableHttpBody = "Streamable HTTP not supported " ;
382383
383384 mockHttpHandler . RequestHandler = ( request ) =>
384385 {
385386 if ( request . Method == HttpMethod . Post )
386387 {
387388 return Task . FromResult ( new HttpResponseMessage
388389 {
389- StatusCode = HttpStatusCode . UnsupportedMediaType ,
390+ StatusCode = HttpStatusCode . NotFound ,
390391 Content = new StringContent ( streamableHttpBody ) ,
391392 } ) ;
392393 }
@@ -412,11 +413,11 @@ public async Task AutoDetectMode_SurfacesStreamableHttpError_WithSseAsInner_When
412413
413414 // The surfaced exception is the original Streamable HTTP error (the real server diagnostic), not the SSE 405.
414415 var httpEx = Assert . IsType < HttpRequestException > ( ex ) ;
415- Assert . Contains ( "415 " , httpEx . Message ) ;
416+ Assert . Contains ( "404 " , httpEx . Message ) ;
416417 Assert . Contains ( streamableHttpBody , httpEx . Message ) ;
417- Assert . Equal ( HttpStatusCode . UnsupportedMediaType , httpEx . Data [ "ModelContextProtocol.HttpStatusCode" ] ) ;
418+ Assert . Equal ( HttpStatusCode . NotFound , httpEx . Data [ "ModelContextProtocol.HttpStatusCode" ] ) ;
418419#if NET
419- Assert . Equal ( HttpStatusCode . UnsupportedMediaType , httpEx . StatusCode ) ;
420+ Assert . Equal ( HttpStatusCode . NotFound , httpEx . StatusCode ) ;
420421#endif
421422
422423 // The SSE fallback failure (the 405 from the GET) is preserved as the inner exception, not dropped.
@@ -482,8 +483,8 @@ public async Task AutoDetectMode_LogsWarning_WhenSseFallbackFailsAfterStreamable
482483 {
483484 return Task . FromResult ( new HttpResponseMessage
484485 {
485- StatusCode = HttpStatusCode . UnsupportedMediaType ,
486- Content = new StringContent ( "Content-Type must be 'application/json' " ) ,
486+ StatusCode = HttpStatusCode . NotFound ,
487+ Content = new StringContent ( "Streamable HTTP not supported " ) ,
487488 } ) ;
488489 }
489490
0 commit comments