Skip to content

Commit b522dee

Browse files
feat: add specific error handling for client connect
1 parent 1c5e549 commit b522dee

File tree

1 file changed

+6
-1
lines changed
  • src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client

1 file changed

+6
-1
lines changed

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/Client.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import kotlinx.serialization.json.JsonElement
1010
import kotlinx.serialization.json.JsonNull
1111
import kotlinx.serialization.json.JsonObject
1212
import kotlinx.serialization.json.JsonPrimitive
13+
import kotlin.coroutines.cancellation.CancellationException
1314

1415
/**
1516
* Options for configuring the MCP client.
@@ -100,7 +101,11 @@ public open class Client(
100101
notification(InitializedNotification())
101102
} catch (error: Throwable) {
102103
close()
103-
throw error
104+
if (error !is CancellationException) {
105+
throw IllegalStateException("Error connecting to transport", error)
106+
} else {
107+
throw error
108+
}
104109
}
105110
}
106111

0 commit comments

Comments
 (0)