Skip to content

Commit 27622da

Browse files
author
Abdullatif.Ghajar
committed
Add test to reproduce modelcontextprotocol#52
1 parent 7d2e993 commit 27622da

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package integration
2+
3+
import io.ktor.client.*
4+
import io.ktor.client.plugins.sse.*
5+
import io.ktor.server.cio.*
6+
import io.ktor.server.engine.*
7+
import io.modelcontextprotocol.kotlin.sdk.Implementation
8+
import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities
9+
import io.modelcontextprotocol.kotlin.sdk.client.Client
10+
import io.modelcontextprotocol.kotlin.sdk.client.mcpSse
11+
import io.modelcontextprotocol.kotlin.sdk.server.Server
12+
import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions
13+
import io.modelcontextprotocol.kotlin.sdk.server.mcp
14+
import kotlinx.coroutines.runBlocking
15+
import org.junit.jupiter.api.Test
16+
import org.junit.jupiter.api.assertDoesNotThrow
17+
import io.ktor.client.engine.cio.CIO as ClientCIO
18+
import io.ktor.server.cio.CIO as ServerCIO
19+
20+
class SseIntegrationTest {
21+
@Test
22+
fun `client should be able to connect to sse server`() { // runTest will cause network timeout issues
23+
runBlocking {
24+
val serverEngine = initServer()
25+
try {
26+
assertDoesNotThrow { initClient() }
27+
} finally {
28+
// Make sure to stop the server
29+
serverEngine.stop(1000, 2000)
30+
}
31+
}
32+
}
33+
34+
private suspend fun initClient(): Client {
35+
return HttpClient(ClientCIO) { install(SSE) }.mcpSse("http://$URL:$PORT")
36+
}
37+
38+
private fun initServer(): EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration> {
39+
val server = Server(
40+
Implementation(name = "sse-e2e-test", version = "1.0.0"),
41+
ServerOptions(capabilities = ServerCapabilities()),
42+
)
43+
44+
return embeddedServer(ServerCIO, host = URL, port = PORT) { mcp { server } }.start(wait = false)
45+
}
46+
47+
companion object {
48+
private const val PORT = 3001
49+
private const val URL = "localhost"
50+
}
51+
}

0 commit comments

Comments
 (0)