Skip to content

Commit 4ebeede

Browse files
committed
refactor(test): simplify MockMcp configurations and improve method readability
1 parent 991317c commit 4ebeede

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

  • kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client

kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/MockMcp.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const val MCP_SESSION_ID_HEADER = "MCP-Session-Id"
2525

2626
internal class MockMcp(verbose: Boolean = false) : AutoCloseable {
2727

28-
private val mokksy: Mokksy = Mokksy(verbose = verbose).apply {
28+
private val mokksy = Mokksy(verbose = verbose).apply {
2929
start()
3030
}
3131

@@ -90,7 +90,7 @@ internal class MockMcp(verbose: Boolean = false) : AutoCloseable {
9090
expectedSessionId: String? = null,
9191
vararg bodyPredicates: (JSONRPCRequest) -> Boolean,
9292
): BuildingStep<JSONRPCRequest> = mokksy.method(
93-
configuration = StubConfiguration(removeAfterMatch = true),
93+
configuration = StubConfiguration.once(),
9494
httpMethod = httpMethod,
9595
requestType = JSONRPCRequest::class,
9696
) {
@@ -219,20 +219,18 @@ internal class MockMcp(verbose: Boolean = false) : AutoCloseable {
219219
sessionId = sessionId,
220220
) respondsWithSseStream {
221221
headers += MCP_SESSION_ID_HEADER to sessionId
222-
this.flow = block.invoke()
222+
flow = block.invoke()
223223
}
224224
}
225225

226226
fun mockUnsubscribeRequest(sessionId: String) {
227227
mokksy.delete(
228-
configuration = StubConfiguration(removeAfterMatch = true),
228+
configuration = StubConfiguration.once(),
229229
requestType = JSONRPCRequest::class,
230230
) {
231231
path("/mcp")
232232
containsHeader(MCP_SESSION_ID_HEADER, sessionId)
233-
} respondsWith {
234-
body = null
235-
}
233+
} respondsWithStatus HttpStatusCode.OK
236234
}
237235

238236
override fun close() {

0 commit comments

Comments
 (0)