From 6485a21e026c8fb43bce77c618ad944e73c2a5de Mon Sep 17 00:00:00 2001 From: devcrocod Date: Thu, 9 Oct 2025 18:50:23 +0200 Subject: [PATCH] Fix Streamable handling to support JSON-only responses --- .../sdk/client/StreamableHttpClientTransport.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt index 50f3a510..c7372ddb 100644 --- a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt +++ b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt @@ -234,10 +234,22 @@ public class StreamableHttpClientTransport( } logger.debug { "Client SSE session started successfully." } } catch (e: SSEClientException) { - if (e.response?.status == HttpStatusCode.MethodNotAllowed) { + val responseStatus = e.response?.status + val responseContentType = e.response?.contentType() + + // 405 means server doesn't support SSE at GET endpoint - this is expected and valid + if (responseStatus == HttpStatusCode.MethodNotAllowed) { logger.info { "Server returned 405 for GET/SSE, stream disabled." } return } + + // If server returns application/json, it means it doesn't support SSE for this session + // This is valid per spec - server can choose to only use JSON responses + if (responseContentType?.match(ContentType.Application.Json) == true) { + logger.info { "Server returned application/json for GET/SSE, using JSON-only mode." } + return + } + _onError(e) throw e }