fix(stdio-client)!: Stdio- and StreamableHttpClientTransport should throw McpException on send when not ready (#487)

This commit is contained in:
Konstantin Pavlov 2026-01-21 08:54:35 +02:00 • committed by GitHub
commit 4d505025b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import io.kotest.matchers.types.shouldBeSameInstanceAs
import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
import io.modelcontextprotocol.kotlin.sdk.client.StdioClientTransport
import io.modelcontextprotocol.kotlin.sdk.types.JSONRPCMessage
@ -151,7 +152,16 @@ class StdioClientTransportErrorHandlingTest {
fun `Send should handle exceptions`(throwable: Throwable, shouldWrap: Boolean, expectedCode: Int?) = runTest {
val sendChannel: Channel<JSONRPCMessage> = mockk(relaxed = true)
val stdin = createNonEmptyBuffer { "id: 1\ndata:\n" }
// Create a stdin Source that never returns EOF to prevent transport from closing
// Use mockk since Source is a sealed interface
val stdin: kotlinx.io.Source = mockk(relaxed = true)
every { stdin.readAtMostTo(any<Buffer>(), any()) } coAnswers {
// Return 0 to indicate no data available (but not EOF)
// This keeps the transport alive without blocking
delay(10) // Small delay to prevent busy-waiting
0L
}
transport = StdioClientTransport(
input = stdin,
output = Buffer(),