Skip to content

Commit da3771b

Browse files
committed
Fix tests
1 parent d08fa34 commit da3771b

File tree

2 files changed

+22
-15
lines changed
  • kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server
  • kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration

2 files changed

+22
-15
lines changed

kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerSession.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,14 @@ public open class ServerSession(private val serverInfo: Implementation, options:
210210

211211
Defined.RootsList -> {
212212
if (clientCapabilities?.roots == null) {
213+
logger.error { "Client capability assertion failed: listing roots not supported" }
213214
throw IllegalStateException("Client does not support listing roots (required for ${method.value})")
214215
}
215216
}
216217

217218
Defined.ElicitationCreate -> {
218219
if (clientCapabilities?.elicitation == null) {
220+
logger.error { "Client capability assertion failed: elicitation not supported" }
219221
throw IllegalStateException("Client does not support elicitation (required for ${method.value})")
220222
}
221223
}
@@ -225,7 +227,7 @@ public open class ServerSession(private val serverInfo: Implementation, options:
225227
}
226228

227229
else -> {
228-
throw IllegalStateException("Server does not support $method")
230+
// For notifications not specifically listed, no assertion by default
229231
}
230232
}
231233
}
@@ -257,7 +259,7 @@ public open class ServerSession(private val serverInfo: Implementation, options:
257259
}
258260
}
259261

260-
Defined.NotificationsResourcesListChanged -> {
262+
Defined.NotificationsToolsListChanged -> {
261263
if (serverCapabilities.tools == null) {
262264
throw IllegalStateException(
263265
"Server does not support notifying of tool list changes (required for ${method.value})",
@@ -280,7 +282,7 @@ public open class ServerSession(private val serverInfo: Implementation, options:
280282
}
281283

282284
else -> {
283-
throw IllegalStateException("Server does not support $method or it's not a notification method")
285+
// For notifications not specifically listed, no assertion by default
284286
}
285287
}
286288
}
@@ -340,7 +342,7 @@ public open class ServerSession(private val serverInfo: Implementation, options:
340342
}
341343

342344
else -> {
343-
throw IllegalStateException("Server does not support $method or it's not a request handler method")
345+
// For notifications not specifically listed, no assertion by default
344346
}
345347
}
346348
}

kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/SseIntegrationTest.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import io.ktor.client.engine.cio.CIO as ClientCIO
3131
import io.ktor.server.cio.CIO as ServerCIO
3232
import io.ktor.server.sse.SSE as ServerSSE
3333

34-
private const val URL = "127.0.0.1"
35-
private const val PORT = 0
36-
3734
class SseIntegrationTest {
3835
@Test
3936
fun `client should be able to connect to sse server`() = runTest {
@@ -44,7 +41,8 @@ class SseIntegrationTest {
4441
withContext(Dispatchers.Default) {
4542
withTimeout(1000) {
4643
server = initServer()
47-
client = initClient()
44+
val port = server.engine.resolvedConnectors().first().port
45+
client = initClient(serverPort=port)
4846
}
4947
}
5048
} finally {
@@ -64,12 +62,12 @@ class SseIntegrationTest {
6462
fun `single sse connection`() = runTest {
6563
var server: EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration>? = null
6664
var client: Client? = null
67-
6865
try {
6966
withContext(Dispatchers.Default) {
7067
withTimeout(1000) {
7168
server = initServer()
72-
client = initClient("Client A")
69+
val port = server.engine.resolvedConnectors().first().port
70+
client = initClient("Client A", port)
7371

7472
val promptA = getPrompt(client, "Client A")
7573
assertTrue { "Client A" in promptA }
@@ -99,8 +97,10 @@ class SseIntegrationTest {
9997
withContext(Dispatchers.Default) {
10098
withTimeout(1000) {
10199
server = initServer()
102-
clientA = initClient("Client A")
103-
clientB = initClient("Client B")
100+
val port = server.engine.resolvedConnectors().first().port
101+
102+
clientA = initClient("Client A", port)
103+
clientB = initClient("Client B", port)
104104

105105
// Step 3: Send a prompt request from Client A
106106
val promptA = getPrompt(clientA, "Client A")
@@ -118,7 +118,7 @@ class SseIntegrationTest {
118118
}
119119
}
120120

121-
private suspend fun initClient(name: String = ""): Client {
121+
private suspend fun initClient(name: String = "", serverPort: Int): Client {
122122
val client = Client(
123123
Implementation(name = name, version = "1.0.0"),
124124
)
@@ -131,7 +131,7 @@ class SseIntegrationTest {
131131
val transport = httpClient.mcpSseTransport {
132132
url {
133133
host = URL
134-
port = PORT
134+
port = serverPort
135135
}
136136
}
137137

@@ -195,7 +195,12 @@ class SseIntegrationTest {
195195
),
196196
)
197197

198-
return (response?.messages?.first()?.content as? TextContent)?.text
198+
return (response.messages.first().content as? TextContent)?.text
199199
?: error("Failed to receive prompt for Client $clientName")
200200
}
201+
202+
companion object {
203+
private const val URL = "127.0.0.1"
204+
private const val PORT = 0
205+
}
201206
}

0 commit comments

Comments
 (0)