Skip to content

Commit 0f60fa5

Browse files
committed
Fix Streamable handling to support JSON-only responses
1 parent d60e8b6 commit 0f60fa5

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
@@ -235,10 +235,22 @@ public class StreamableHttpClientTransport(
235235
}
236236
logger.debug { "Client SSE session started successfully." }
237237
} catch (e: SSEClientException) {
238-
if (e.response?.status == HttpStatusCode.MethodNotAllowed) {
238+
val responseStatus = e.response?.status
239+
val responseContentType = e.response?.contentType()
240+
241+
// 405 means server doesn't support SSE at GET endpoint - this is expected and valid
242+
if (responseStatus == HttpStatusCode.MethodNotAllowed) {
239243
logger.info { "Server returned 405 for GET/SSE, stream disabled." }
240244
return
241245
}
246+
247+
// If server returns application/json, it means it doesn't support SSE for this session
248+
// This is valid per spec - server can choose to only use JSON responses
249+
if (responseContentType?.match(ContentType.Application.Json) == true) {
250+
logger.info { "Server returned application/json for GET/SSE, using JSON-only mode." }
251+
return
252+
}
253+
242254
_onError(e)
243255
throw e
244256
}

0 commit comments

Comments
 (0)