Skip to content

Commit 6485a21

Browse files
committed
Fix Streamable handling to support JSON-only responses
1 parent dcb4f21 commit 6485a21

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,22 @@ public class StreamableHttpClientTransport(
234234
}
235235
logger.debug { "Client SSE session started successfully." }
236236
} catch (e: SSEClientException) {
237-
if (e.response?.status == HttpStatusCode.MethodNotAllowed) {
237+
val responseStatus = e.response?.status
238+
val responseContentType = e.response?.contentType()
239+
240+
// 405 means server doesn't support SSE at GET endpoint - this is expected and valid
241+
if (responseStatus == HttpStatusCode.MethodNotAllowed) {
238242
logger.info { "Server returned 405 for GET/SSE, stream disabled." }
239243
return
240244
}
245+
246+
// If server returns application/json, it means it doesn't support SSE for this session
247+
// This is valid per spec - server can choose to only use JSON responses
248+
if (responseContentType?.match(ContentType.Application.Json) == true) {
249+
logger.info { "Server returned application/json for GET/SSE, using JSON-only mode." }
250+
return
251+
}
252+
241253
_onError(e)
242254
throw e
243255
}

0 commit comments

Comments
 (0)