Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.modelcontextprotocol.kotlin.sdk.client

Check failure on line 1 in integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/WebSocketTransportTest.kt

View workflow job for this annotation

GitHub Actions / Build (Linux Tests)

WebSocketTransportTest.should start then close cleanly()[jvm]

org.opentest4j.AssertionFailedError: Block failed after 2.000900139s; attempted 71 time(s) The first error was caused by: expected:<false> but was:<true> org.opentest4j.AssertionFailedError: expected:<false> but was:<true> at io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest$testTransportOpenClose$4.invokeSuspend(BaseTransportTest.kt:27) at io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest$testTransportOpenClose$4.invoke(BaseTransportTest.kt) at io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest$testTransportOpenClose$4.invoke(BaseTransportTest.kt) at io.kotest.assertions.nondeterministic.EventuallyKt.runIterations(eventually.kt:114) at io.kotest.assertions.nondeterministic.EventuallyKt.access$runIterations(eventually.kt:1) at io.kotest.assertions.nondeterministic.EventuallyKt$eventually$6.invokeSuspend(eventually.kt:92) at io.kotest.assertions.nondeterministic.EventuallyKt$eventually$6.invoke(eventually.kt) at io.kotest.assertions.nondeterministic.EventuallyKt$eventually$6.invoke(eventually.kt) at io.kotest.common.WithNonVirtualTimeoutKt$withWallClockTimeout$2$blockDeferred$1.invokeSuspend(withNonVirtualTimeout.kt:50) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704) The last error was caused by: expected:<false> but was:<true> org.opentest4j.AssertionFailedError: expected:<false> but was:<true> at io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest$testTransportOpenClose$4.invokeSuspend(BaseTransportTest.kt:27) at io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest$testTransportOpenClose$4.invoke(BaseTransportTest.kt) at io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest$testTransportOpenClose$4.invoke(BaseTransportTest.kt) at io.kotest.assertions.nondeterministic.EventuallyKt.runIterations(eventually.kt:114) at io.kotest.assertions.nondeterministic.EventuallyKt.access$runIterations(eventually.kt:1) at io.kotest.assertions.nondeterministic.EventuallyKt$runIterations$1.invokeSuspend(eventually.kt) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)

import io.ktor.server.testing.testApplication
import io.ktor.server.websocket.WebSockets
Expand All @@ -6,12 +6,13 @@
import io.modelcontextprotocol.kotlin.sdk.server.mcpWebSocketTransport
import io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest
import kotlinx.coroutines.CompletableDeferred
import kotlin.test.Ignore
import kotlin.test.Test
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import java.util.concurrent.TimeUnit

@Timeout(30, unit = TimeUnit.SECONDS)
class WebSocketTransportTest : BaseTransportTest() {
@Test
@Ignore // "Test disabled for investigation #17"
fun `should start then close cleanly`() = testApplication {
install(WebSockets)
routing {
Expand All @@ -26,7 +27,6 @@
}

@Test
@Ignore // "Test disabled for investigation #17"
fun `should read messages`() = testApplication {
val clientFinished = CompletableDeferred<Unit>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import io.ktor.websocket.close
import io.ktor.websocket.readText
import io.modelcontextprotocol.kotlin.sdk.types.JSONRPCMessage
import io.modelcontextprotocol.kotlin.sdk.types.McpJson
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineName
Comment on lines 8 to 11
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CancellationException is imported from kotlinx.coroutines here, but other commonMain code in this module uses kotlin.coroutines.cancellation.CancellationException (e.g., AbstractClientTransport). Consider switching to the stdlib import for consistency and to avoid confusion with java.util.concurrent.CancellationException on JVM.

Copilot uses AI. Check for mistakes.
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.ClosedReceiveChannelException
import kotlinx.coroutines.job
Expand Down Expand Up @@ -81,9 +81,8 @@ public abstract class WebSocketMcpTransport : AbstractTransport() {
}
}

@OptIn(InternalCoroutinesApi::class)
session.coroutineContext.job.invokeOnCompletion {
if (it != null) {
if (it != null && it !is CancellationException) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t the CancellationException be also rethrown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, rethrowing here would be incorrect

_onError.invoke(it)
} else {
invokeOnCloseCallback()
Expand Down
Loading