Skip to content

Commit 74aeaff

Browse files
committed
Added the returned serverInstructions to the client and added verification to the ServerTests (addresses PR feedback)
1 parent 1a714d7 commit 74aeaff

File tree

3 files changed

+21
-29
lines changed
  • kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client
  • kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server
  • kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server

3 files changed

+21
-29
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ public open class Client(private val clientInfo: Implementation, options: Client
9191
public var serverCapabilities: ServerCapabilities? = null
9292
private set
9393

94+
/**
95+
* Optional human-readable instructions or description for the client.
96+
* This can be used to provide context or usage guidelines for users interacting with the client.
97+
*/
98+
public var serverInstructions: String? = null
99+
private set
100+
94101
/**
95102
* Retrieves the server's reported version information after initialization.
96103
*
@@ -154,6 +161,7 @@ public open class Client(private val clientInfo: Implementation, options: Client
154161

155162
serverCapabilities = result.capabilities
156163
serverVersion = result.serverInfo
164+
serverInstructions = result.instructions
157165

158166
notification(InitializedNotification())
159167
} catch (error: Throwable) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public open class ServerSession(
255255

256256
Defined.NotificationsResourcesUpdated,
257257
Defined.NotificationsResourcesListChanged,
258-
-> {
258+
-> {
259259
if (serverCapabilities.resources == null) {
260260
throw IllegalStateException(
261261
"Server does not support notifying about resources (required for ${method.value})",
@@ -281,7 +281,7 @@ public open class ServerSession(
281281

282282
Defined.NotificationsCancelled,
283283
Defined.NotificationsProgress,
284-
-> {
284+
-> {
285285
// Always allowed
286286
}
287287

@@ -316,7 +316,7 @@ public open class ServerSession(
316316

317317
Defined.PromptsGet,
318318
Defined.PromptsList,
319-
-> {
319+
-> {
320320
if (serverCapabilities.prompts == null) {
321321
throw IllegalStateException("Server does not support prompts (required for $method)")
322322
}
@@ -327,15 +327,15 @@ public open class ServerSession(
327327
Defined.ResourcesRead,
328328
Defined.ResourcesSubscribe,
329329
Defined.ResourcesUnsubscribe,
330-
-> {
330+
-> {
331331
if (serverCapabilities.resources == null) {
332332
throw IllegalStateException("Server does not support resources (required for $method)")
333333
}
334334
}
335335

336336
Defined.ToolsCall,
337337
Defined.ToolsList,
338-
-> {
338+
-> {
339339
if (serverCapabilities.tools == null) {
340340
throw IllegalStateException("Server does not support tools (required for $method)")
341341
}

kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerTest.kt

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import kotlinx.coroutines.CompletableDeferred
1919
import kotlinx.coroutines.launch
2020
import kotlinx.coroutines.test.runTest
2121
import org.junit.jupiter.api.Test
22+
import org.junit.jupiter.api.assertNull
2223
import org.junit.jupiter.api.assertThrows
2324
import kotlin.test.assertEquals
2425
import kotlin.test.assertFalse
@@ -485,32 +486,15 @@ class ServerTest {
485486
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
486487
val client = Client(clientInfo = Implementation(name = "test client", version = "1.0"))
487488

488-
launch { client.connect(clientTransport) }
489-
launch { server.connect(serverTransport) }
489+
server.connect(serverTransport)
490+
client.connect(clientTransport)
490491

491-
// The test passes if the server can be created with instructions without throwing
492-
assertTrue(true, "Server should accept instructions parameter")
492+
assertEquals(instructions, client.serverInstructions)
493493
}
494494

495-
@Test
496-
fun `Server constructor should work with null instructions`() = runTest {
497-
val serverInfo = Implementation(name = "test server", version = "1.0")
498-
val serverOptions = ServerOptions(capabilities = ServerCapabilities())
499-
500-
val server = Server(serverInfo, serverOptions, null)
501-
502-
// Test that server works with null instructions
503-
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
504-
val client = Client(clientInfo = Implementation(name = "test client", version = "1.0"))
505-
506-
launch { client.connect(clientTransport) }
507-
launch { server.connect(serverTransport) }
508-
509-
assertTrue(true, "Server should accept null instructions parameter")
510-
}
511495

512496
@Test
513-
fun `Server constructor should work with default instructions parameter`() = runTest {
497+
fun `Server constructor should work without instructions parameter`() = runTest {
514498
val serverInfo = Implementation(name = "test server", version = "1.0")
515499
val serverOptions = ServerOptions(capabilities = ServerCapabilities())
516500

@@ -520,9 +504,9 @@ class ServerTest {
520504
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
521505
val client = Client(clientInfo = Implementation(name = "test client", version = "1.0"))
522506

523-
launch { client.connect(clientTransport) }
524-
launch { server.connect(serverTransport) }
507+
server.connect(serverTransport)
508+
client.connect(clientTransport)
525509

526-
assertTrue(true, "Server should work with default instructions parameter")
510+
assertNull(client.serverInstructions)
527511
}
528512
}

0 commit comments

Comments
 (0)