@@ -10,10 +10,10 @@ import io.ktor.client.request.setBody
1010import io.ktor.client.statement.bodyAsText
1111import io.ktor.http.ContentType
1212import io.ktor.http.HttpHeaders
13- import io.ktor.http.Url
13+ import io.ktor.http.URLBuilder
1414import io.ktor.http.append
1515import io.ktor.http.isSuccess
16- import io.ktor.http.protocolWithAuthority
16+ import io.ktor.http.takeFrom
1717import io.modelcontextprotocol.kotlin.sdk.shared.AbstractTransport
1818import io.modelcontextprotocol.kotlin.sdk.shared.TransportSendOptions
1919import io.modelcontextprotocol.kotlin.sdk.types.JSONRPCMessage
@@ -58,14 +58,7 @@ public class SseClientTransport(
5858 private var job: Job ? = null
5959
6060 private val baseUrl: String by lazy {
61- session.call.request.url.let { url ->
62- val path = url.encodedPath
63- when {
64- path.isEmpty() -> url.protocolWithAuthority
65- path.endsWith(" /" ) -> url.protocolWithAuthority + path.removeSuffix(" /" )
66- else -> url.protocolWithAuthority + path.take(path.lastIndexOf(" /" ))
67- }
68- }
61+ session.call.request.url.toString()
6962 }
7063
7164 override suspend fun start () {
@@ -159,10 +152,9 @@ public class SseClientTransport(
159152 }
160153 }
161154
162- private fun handleEndpoint (eventData : String ) {
155+ private fun handleEndpoint (endpointData : String ) {
163156 try {
164- val path = if (eventData.startsWith(" /" )) eventData.substring(1 ) else eventData
165- val endpointUrl = Url (" $baseUrl /$path " )
157+ val endpointUrl = URLBuilder (baseUrl).takeFrom(endpointData).build()
166158 endpoint.complete(endpointUrl.toString())
167159 logger.debug { " Client connected to endpoint: $endpointUrl " }
168160 } catch (e: Throwable ) {
0 commit comments