@@ -42,8 +42,6 @@ import kotlin.concurrent.atomics.AtomicBoolean
4242import kotlin.concurrent.atomics.ExperimentalAtomicApi
4343import kotlin.time.Duration
4444
45- private val logger = KotlinLogging .logger {}
46-
4745private const val MCP_SESSION_ID_HEADER = " mcp-session-id"
4846private const val MCP_PROTOCOL_VERSION_HEADER = " mcp-protocol-version"
4947private const val MCP_RESUMPTION_TOKEN_HEADER = " Last-Event-ID"
@@ -67,6 +65,10 @@ public class StreamableHttpClientTransport(
6765 private val requestBuilder : HttpRequestBuilder .() -> Unit = {},
6866) : AbstractTransport() {
6967
68+ private companion object {
69+ private val logger = KotlinLogging .logger {}
70+ }
71+
7072 public var sessionId: String? = null
7173 private set
7274 public var protocolVersion: String? = null
@@ -316,7 +318,10 @@ public class StreamableHttpClientTransport(
316318 var id: String? = null
317319 var eventName: String? = null
318320
319- suspend fun dispatch (data : String ) {
321+ suspend fun dispatch (id : String? , eventName : String? , data : String ) {
322+ if (data.isBlank()) {
323+ return
324+ }
320325 id?.let {
321326 lastEventId = it
322327 onResumptionToken?.invoke(it)
@@ -335,16 +340,16 @@ public class StreamableHttpClientTransport(
335340 throw it
336341 }
337342 }
338- // reset
339- id = null
340- eventName = null
341- sb.clear()
342343 }
343344
344345 while (! channel.isClosedForRead) {
345346 val line = channel.readUTF8Line() ? : break
346347 if (line.isEmpty()) {
347- dispatch(sb.toString())
348+ dispatch(id = id, eventName = eventName, data = sb.toString())
349+ // reset
350+ id = null
351+ eventName = null
352+ sb.clear()
348353 continue
349354 }
350355 when {
0 commit comments