Add ktlint (#213)
* Add ktlint * Simplify `initClient` function and clean imports in SseIntegrationTest.
This commit is contained in:
parent
b0f075900a
commit
91cf1205af
9 changed files with 800 additions and 758 deletions
|
|
@ -66,13 +66,13 @@ class ClientTest {
|
|||
capabilities = ServerCapabilities(),
|
||||
serverInfo = Implementation(
|
||||
name = "test",
|
||||
version = "1.0"
|
||||
)
|
||||
version = "1.0",
|
||||
),
|
||||
)
|
||||
|
||||
val response = JSONRPCResponse(
|
||||
id = message.id,
|
||||
result = result
|
||||
result = result,
|
||||
)
|
||||
|
||||
_onMessage.invoke(response)
|
||||
|
|
@ -85,13 +85,13 @@ class ClientTest {
|
|||
val client = Client(
|
||||
clientInfo = Implementation(
|
||||
name = "test client",
|
||||
version = "1.0"
|
||||
version = "1.0",
|
||||
),
|
||||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
sampling = EmptyJsonObject
|
||||
)
|
||||
)
|
||||
sampling = EmptyJsonObject,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
client.connect(clientTransport)
|
||||
|
|
@ -100,7 +100,7 @@ class ClientTest {
|
|||
|
||||
@Test
|
||||
fun `should initialize with supported older protocol version`() = runTest {
|
||||
val OLD_VERSION = SUPPORTED_PROTOCOL_VERSIONS[1]
|
||||
val oldVersion = SUPPORTED_PROTOCOL_VERSIONS[1]
|
||||
val clientTransport = object : AbstractTransport() {
|
||||
override suspend fun start() {}
|
||||
|
||||
|
|
@ -109,17 +109,17 @@ class ClientTest {
|
|||
check(message.method == Method.Defined.Initialize.value)
|
||||
|
||||
val result = InitializeResult(
|
||||
protocolVersion = OLD_VERSION,
|
||||
protocolVersion = oldVersion,
|
||||
capabilities = ServerCapabilities(),
|
||||
serverInfo = Implementation(
|
||||
name = "test",
|
||||
version = "1.0"
|
||||
)
|
||||
version = "1.0",
|
||||
),
|
||||
)
|
||||
|
||||
val response = JSONRPCResponse(
|
||||
id = message.id,
|
||||
result = result
|
||||
result = result,
|
||||
)
|
||||
_onMessage.invoke(response)
|
||||
}
|
||||
|
|
@ -131,19 +131,19 @@ class ClientTest {
|
|||
val client = Client(
|
||||
clientInfo = Implementation(
|
||||
name = "test client",
|
||||
version = "1.0"
|
||||
version = "1.0",
|
||||
),
|
||||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
sampling = EmptyJsonObject
|
||||
)
|
||||
)
|
||||
sampling = EmptyJsonObject,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
client.connect(clientTransport)
|
||||
assertEquals(
|
||||
Implementation("test", "1.0"),
|
||||
client.serverVersion
|
||||
client.serverVersion,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -162,13 +162,13 @@ class ClientTest {
|
|||
capabilities = ServerCapabilities(),
|
||||
serverInfo = Implementation(
|
||||
name = "test",
|
||||
version = "1.0"
|
||||
)
|
||||
version = "1.0",
|
||||
),
|
||||
)
|
||||
|
||||
val response = JSONRPCResponse(
|
||||
id = message.id,
|
||||
result = result
|
||||
result = result,
|
||||
)
|
||||
|
||||
_onMessage.invoke(response)
|
||||
|
|
@ -182,9 +182,9 @@ class ClientTest {
|
|||
val client = Client(
|
||||
clientInfo = Implementation(
|
||||
name = "test client",
|
||||
version = "1.0"
|
||||
version = "1.0",
|
||||
),
|
||||
options = ClientOptions()
|
||||
options = ClientOptions(),
|
||||
)
|
||||
|
||||
assertFailsWith<IllegalStateException>("Server's protocol version is not supported: invalid-version") {
|
||||
|
|
@ -214,9 +214,9 @@ class ClientTest {
|
|||
val client = Client(
|
||||
clientInfo = Implementation(
|
||||
name = "test client",
|
||||
version = "1.0"
|
||||
version = "1.0",
|
||||
),
|
||||
options = ClientOptions()
|
||||
options = ClientOptions(),
|
||||
)
|
||||
|
||||
val exception = assertFailsWith<IllegalStateException> {
|
||||
|
|
@ -233,12 +233,12 @@ class ClientTest {
|
|||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(null, null),
|
||||
tools = ServerCapabilities.Tools(null)
|
||||
)
|
||||
tools = ServerCapabilities.Tools(null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
server.setRequestHandler<InitializeRequest>(Method.Defined.Initialize) { _, _ ->
|
||||
|
|
@ -246,9 +246,9 @@ class ClientTest {
|
|||
protocolVersion = LATEST_PROTOCOL_VERSION,
|
||||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(null, null),
|
||||
tools = ServerCapabilities.Tools(null)
|
||||
tools = ServerCapabilities.Tools(null),
|
||||
),
|
||||
serverInfo = Implementation(name = "test", version = "1.0")
|
||||
serverInfo = Implementation(name = "test", version = "1.0"),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ class ClientTest {
|
|||
clientInfo = Implementation(name = "test client", version = "1.0"),
|
||||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities(sampling = EmptyJsonObject),
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
listOf(
|
||||
|
|
@ -275,7 +275,7 @@ class ClientTest {
|
|||
},
|
||||
launch {
|
||||
server.connect(serverTransport)
|
||||
}
|
||||
},
|
||||
).joinAll()
|
||||
|
||||
// Server supports resources and tools, but not prompts
|
||||
|
|
@ -299,16 +299,16 @@ class ClientTest {
|
|||
fun `should respect client notification capabilities`() = runTest {
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
ServerOptions(capabilities = ServerCapabilities())
|
||||
ServerOptions(capabilities = ServerCapabilities()),
|
||||
)
|
||||
|
||||
val client = Client(
|
||||
clientInfo = Implementation(name = "test client", version = "1.0"),
|
||||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
roots = ClientCapabilities.Roots(listChanged = true)
|
||||
)
|
||||
)
|
||||
roots = ClientCapabilities.Roots(listChanged = true),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
|
||||
|
|
@ -321,7 +321,7 @@ class ClientTest {
|
|||
launch {
|
||||
server.connect(serverTransport)
|
||||
println("Server connected")
|
||||
}
|
||||
},
|
||||
).joinAll()
|
||||
|
||||
// This should not throw because the client supports roots.listChanged
|
||||
|
|
@ -333,7 +333,7 @@ class ClientTest {
|
|||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities(),
|
||||
// enforceStrictCapabilities = true // TODO()
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
clientWithoutCapability.connect(clientTransport)
|
||||
|
|
@ -354,16 +354,16 @@ class ClientTest {
|
|||
ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
logging = EmptyJsonObject,
|
||||
resources = ServerCapabilities.Resources(listChanged = true, subscribe = null)
|
||||
)
|
||||
)
|
||||
resources = ServerCapabilities.Resources(listChanged = true, subscribe = null),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val client = Client(
|
||||
clientInfo = Implementation(name = "test client", version = "1.0"),
|
||||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities()
|
||||
)
|
||||
capabilities = ClientCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
|
||||
|
|
@ -376,7 +376,7 @@ class ClientTest {
|
|||
launch {
|
||||
server.connect(serverTransport)
|
||||
println("Server connected")
|
||||
}
|
||||
},
|
||||
).joinAll()
|
||||
|
||||
// These should not throw
|
||||
|
|
@ -389,9 +389,9 @@ class ClientTest {
|
|||
LoggingMessageNotification(
|
||||
params = LoggingMessageNotification.Params(
|
||||
level = LoggingLevel.info,
|
||||
data = jsonObject
|
||||
)
|
||||
)
|
||||
data = jsonObject,
|
||||
),
|
||||
),
|
||||
)
|
||||
server.sendResourceListChanged()
|
||||
|
||||
|
|
@ -410,10 +410,10 @@ class ClientTest {
|
|||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(
|
||||
listChanged = null,
|
||||
subscribe = null
|
||||
)
|
||||
)
|
||||
)
|
||||
subscribe = null,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val def = CompletableDeferred<Unit>()
|
||||
|
|
@ -435,7 +435,7 @@ class ClientTest {
|
|||
|
||||
val client = Client(
|
||||
clientInfo = Implementation(name = "test client", version = "1.0"),
|
||||
options = ClientOptions(capabilities = ClientCapabilities())
|
||||
options = ClientOptions(capabilities = ClientCapabilities()),
|
||||
)
|
||||
|
||||
listOf(
|
||||
|
|
@ -446,7 +446,7 @@ class ClientTest {
|
|||
launch {
|
||||
server.connect(serverTransport)
|
||||
println("Server connected")
|
||||
}
|
||||
},
|
||||
).joinAll()
|
||||
|
||||
val defCancel = CompletableDeferred<Unit>()
|
||||
|
|
@ -472,10 +472,10 @@ class ClientTest {
|
|||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(
|
||||
listChanged = null,
|
||||
subscribe = null
|
||||
)
|
||||
)
|
||||
)
|
||||
subscribe = null,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
server.setRequestHandler<ListResourcesRequest>(Method.Defined.ResourcesList) { _, _ ->
|
||||
|
|
@ -495,7 +495,7 @@ class ClientTest {
|
|||
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
|
||||
val client = Client(
|
||||
clientInfo = Implementation(name = "test client", version = "1.0"),
|
||||
options = ClientOptions(capabilities = ClientCapabilities())
|
||||
options = ClientOptions(capabilities = ClientCapabilities()),
|
||||
)
|
||||
|
||||
listOf(
|
||||
|
|
@ -506,7 +506,7 @@ class ClientTest {
|
|||
launch {
|
||||
server.connect(serverTransport)
|
||||
println("Server connected")
|
||||
}
|
||||
},
|
||||
).joinAll()
|
||||
|
||||
// Request with 1 msec timeout should fail immediately
|
||||
|
|
@ -523,13 +523,13 @@ class ClientTest {
|
|||
val client = Client(
|
||||
clientInfo = Implementation(
|
||||
name = "test client",
|
||||
version = "1.0"
|
||||
version = "1.0",
|
||||
),
|
||||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
sampling = EmptyJsonObject
|
||||
)
|
||||
)
|
||||
sampling = EmptyJsonObject,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
client.setRequestHandler<CreateMessageRequest>(Method.Defined.SamplingCreateMessage) { _, _ ->
|
||||
|
|
@ -537,8 +537,8 @@ class ClientTest {
|
|||
model = "test-model",
|
||||
role = Role.assistant,
|
||||
content = TextContent(
|
||||
text = "Test response"
|
||||
)
|
||||
text = "Test response",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -551,12 +551,12 @@ class ClientTest {
|
|||
fun `JSONRPCRequest with ToolsList method and default params returns list of tools`() = runTest {
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
tools = ServerCapabilities.Tools(null)
|
||||
)
|
||||
tools = ServerCapabilities.Tools(null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
server.setRequestHandler<InitializeRequest>(Method.Defined.Initialize) { _, _ ->
|
||||
|
|
@ -564,9 +564,9 @@ class ClientTest {
|
|||
protocolVersion = LATEST_PROTOCOL_VERSION,
|
||||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(null, null),
|
||||
tools = ServerCapabilities.Tools(null)
|
||||
tools = ServerCapabilities.Tools(null),
|
||||
),
|
||||
serverInfo = Implementation(name = "test", version = "1.0")
|
||||
serverInfo = Implementation(name = "test", version = "1.0"),
|
||||
)
|
||||
}
|
||||
val serverListToolsResult = ListToolsResult(
|
||||
|
|
@ -577,9 +577,10 @@ class ClientTest {
|
|||
description = "testTool description",
|
||||
annotations = null,
|
||||
inputSchema = Tool.Input(),
|
||||
outputSchema = null
|
||||
)
|
||||
), nextCursor = null
|
||||
outputSchema = null,
|
||||
),
|
||||
),
|
||||
nextCursor = null,
|
||||
)
|
||||
|
||||
server.setRequestHandler<ListToolsRequest>(Method.Defined.ToolsList) { _, _ ->
|
||||
|
|
@ -592,7 +593,7 @@ class ClientTest {
|
|||
clientInfo = Implementation(name = "test client", version = "1.0"),
|
||||
options = ClientOptions(
|
||||
capabilities = ClientCapabilities(sampling = EmptyJsonObject),
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
var receivedMessage: JSONRPCMessage? = null
|
||||
|
|
@ -606,14 +607,14 @@ class ClientTest {
|
|||
},
|
||||
launch {
|
||||
server.connect(serverTransport)
|
||||
}
|
||||
},
|
||||
).joinAll()
|
||||
|
||||
val serverCapabilities = client.serverCapabilities
|
||||
assertEquals(ServerCapabilities.Tools(null), serverCapabilities?.tools)
|
||||
|
||||
val request = JSONRPCRequest(
|
||||
method = Method.Defined.ToolsList.value
|
||||
method = Method.Defined.ToolsList.value,
|
||||
)
|
||||
clientTransport.send(request)
|
||||
|
||||
|
|
@ -631,13 +632,13 @@ class ClientTest {
|
|||
Implementation(name = "test client", version = "1.0"),
|
||||
ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
roots = ClientCapabilities.Roots(null)
|
||||
)
|
||||
)
|
||||
roots = ClientCapabilities.Roots(null),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val clientRoots = listOf(
|
||||
Root(uri = "file:///test-root", name = "testRoot")
|
||||
Root(uri = "file:///test-root", name = "testRoot"),
|
||||
)
|
||||
|
||||
client.addRoots(clientRoots)
|
||||
|
|
@ -647,13 +648,13 @@ class ClientTest {
|
|||
val server = Server(
|
||||
serverInfo = Implementation(name = "test server", version = "1.0"),
|
||||
options = ServerOptions(
|
||||
capabilities = ServerCapabilities()
|
||||
)
|
||||
capabilities = ServerCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
listOf(
|
||||
launch { client.connect(clientTransport) },
|
||||
launch { server.connect(serverTransport) }
|
||||
launch { server.connect(serverTransport) },
|
||||
).joinAll()
|
||||
|
||||
val clientCapabilities = server.clientCapabilities
|
||||
|
|
@ -669,8 +670,8 @@ class ClientTest {
|
|||
val client = Client(
|
||||
Implementation(name = "test client", version = "1.0"),
|
||||
ClientOptions(
|
||||
capabilities = ClientCapabilities()
|
||||
)
|
||||
capabilities = ClientCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
// Verify that adding a root throws an exception
|
||||
|
|
@ -685,8 +686,8 @@ class ClientTest {
|
|||
val client = Client(
|
||||
Implementation(name = "test client", version = "1.0"),
|
||||
ClientOptions(
|
||||
capabilities = ClientCapabilities()
|
||||
)
|
||||
capabilities = ClientCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
// Verify that removing a root throws an exception
|
||||
|
|
@ -702,9 +703,9 @@ class ClientTest {
|
|||
Implementation(name = "test client", version = "1.0"),
|
||||
ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
roots = ClientCapabilities.Roots(null)
|
||||
)
|
||||
)
|
||||
roots = ClientCapabilities.Roots(null),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
// Add some roots
|
||||
|
|
@ -712,7 +713,7 @@ class ClientTest {
|
|||
listOf(
|
||||
Root(uri = "file:///test-root1", name = "testRoot1"),
|
||||
Root(uri = "file:///test-root2", name = "testRoot2"),
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
// Remove a root
|
||||
|
|
@ -728,9 +729,9 @@ class ClientTest {
|
|||
Implementation(name = "test client", version = "1.0"),
|
||||
ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
roots = ClientCapabilities.Roots(null)
|
||||
)
|
||||
)
|
||||
roots = ClientCapabilities.Roots(null),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
// Add some roots
|
||||
|
|
@ -738,12 +739,12 @@ class ClientTest {
|
|||
listOf(
|
||||
Root(uri = "file:///test-root1", name = "testRoot1"),
|
||||
Root(uri = "file:///test-root2", name = "testRoot2"),
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
// Remove multiple roots
|
||||
val result = client.removeRoots(
|
||||
listOf("file:///test-root1", "file:///test-root2")
|
||||
listOf("file:///test-root1", "file:///test-root2"),
|
||||
)
|
||||
|
||||
// Verify the root was removed
|
||||
|
|
@ -756,9 +757,9 @@ class ClientTest {
|
|||
Implementation(name = "test client", version = "1.0"),
|
||||
ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
roots = ClientCapabilities.Roots(listChanged = true)
|
||||
)
|
||||
)
|
||||
roots = ClientCapabilities.Roots(listChanged = true),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
|
||||
|
|
@ -766,8 +767,8 @@ class ClientTest {
|
|||
val server = Server(
|
||||
serverInfo = Implementation(name = "test server", version = "1.0"),
|
||||
options = ServerOptions(
|
||||
capabilities = ServerCapabilities()
|
||||
)
|
||||
capabilities = ServerCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
// Track notifications
|
||||
|
|
@ -779,14 +780,14 @@ class ClientTest {
|
|||
|
||||
listOf(
|
||||
launch { client.connect(clientTransport) },
|
||||
launch { server.connect(serverTransport) }
|
||||
launch { server.connect(serverTransport) },
|
||||
).joinAll()
|
||||
|
||||
client.sendRootsListChanged()
|
||||
|
||||
assertTrue(
|
||||
rootListChangedNotificationReceived,
|
||||
"Notification should be sent when sendRootsListChanged is called"
|
||||
"Notification should be sent when sendRootsListChanged is called",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -795,8 +796,8 @@ class ClientTest {
|
|||
val client = Client(
|
||||
Implementation(name = "test client", version = "1.0"),
|
||||
ClientOptions(
|
||||
capabilities = ClientCapabilities()
|
||||
)
|
||||
capabilities = ClientCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair()
|
||||
|
|
@ -804,13 +805,13 @@ class ClientTest {
|
|||
val server = Server(
|
||||
serverInfo = Implementation(name = "test server", version = "1.0"),
|
||||
options = ServerOptions(
|
||||
capabilities = ServerCapabilities()
|
||||
)
|
||||
capabilities = ServerCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
listOf(
|
||||
launch { client.connect(clientTransport) },
|
||||
launch { server.connect(serverTransport) }
|
||||
launch { server.connect(serverTransport) },
|
||||
).joinAll()
|
||||
|
||||
// Verify that creating an elicitation throws an exception
|
||||
|
|
@ -823,13 +824,13 @@ class ClientTest {
|
|||
put("type", "string")
|
||||
}
|
||||
},
|
||||
required = listOf("name")
|
||||
)
|
||||
required = listOf("name"),
|
||||
),
|
||||
)
|
||||
}
|
||||
assertEquals(
|
||||
"Client does not support elicitation (required for elicitation/create)",
|
||||
exception.message
|
||||
exception.message,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -840,8 +841,8 @@ class ClientTest {
|
|||
ClientOptions(
|
||||
capabilities = ClientCapabilities(
|
||||
elicitation = EmptyJsonObject,
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val elicitationMessage = "Please provide your GitHub username"
|
||||
|
|
@ -851,7 +852,7 @@ class ClientTest {
|
|||
put("type", "string")
|
||||
}
|
||||
},
|
||||
required = listOf("name")
|
||||
required = listOf("name"),
|
||||
)
|
||||
|
||||
val elicitationResultAction = CreateElicitationResult.Action.accept
|
||||
|
|
@ -865,7 +866,7 @@ class ClientTest {
|
|||
|
||||
CreateElicitationResult(
|
||||
action = elicitationResultAction,
|
||||
content = elicitationResultContent
|
||||
content = elicitationResultContent,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -874,18 +875,18 @@ class ClientTest {
|
|||
val server = Server(
|
||||
serverInfo = Implementation(name = "test server", version = "1.0"),
|
||||
options = ServerOptions(
|
||||
capabilities = ServerCapabilities()
|
||||
)
|
||||
capabilities = ServerCapabilities(),
|
||||
),
|
||||
)
|
||||
|
||||
listOf(
|
||||
launch { client.connect(clientTransport) },
|
||||
launch { server.connect(serverTransport) }
|
||||
launch { server.connect(serverTransport) },
|
||||
).joinAll()
|
||||
|
||||
val result = server.createElicitation(
|
||||
message = elicitationMessage,
|
||||
requestedSchema = requestedSchema
|
||||
requestedSchema = requestedSchema,
|
||||
)
|
||||
|
||||
assertEquals(elicitationResultAction, result.action)
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ class SseTransportTest : BaseTransportTest() {
|
|||
mcpServer = Server(
|
||||
serverInfo = Implementation(
|
||||
name = "test-server",
|
||||
version = "1.0"
|
||||
version = "1.0",
|
||||
),
|
||||
options = ServerOptions(ServerCapabilities())
|
||||
options = ServerOptions(ServerCapabilities()),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class InMemoryTransportTest {
|
|||
|
||||
assertFailsWith<IllegalStateException> {
|
||||
clientTransport.send(
|
||||
InitializedNotification().toJSON()
|
||||
InitializedNotification().toJSON(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ class SseIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun initClient(port: Int): Client {
|
||||
return HttpClient(ClientCIO) { install(ClientSSE) }.mcpSse("http://$URL:$port")
|
||||
}
|
||||
private suspend fun initClient(port: Int): Client = HttpClient(ClientCIO) {
|
||||
install(ClientSSE)
|
||||
}.mcpSse("http://$URL:$port")
|
||||
|
||||
private suspend fun initServer(): EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration> {
|
||||
val server = Server(
|
||||
|
|
@ -60,4 +60,4 @@ class SseIntegrationTest {
|
|||
}
|
||||
}.startSuspend(wait = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ abstract class BaseTransportTest {
|
|||
}
|
||||
|
||||
val messages = listOf<JSONRPCMessage>(
|
||||
PingRequest().toJSON(), InitializedNotification().toJSON()
|
||||
PingRequest().toJSON(),
|
||||
InitializedNotification().toJSON(),
|
||||
)
|
||||
|
||||
val readMessages = mutableListOf<JSONRPCMessage>()
|
||||
|
|
|
|||
|
|
@ -44,4 +44,4 @@ class InMemoryTransport : AbstractTransport() {
|
|||
|
||||
other._onMessage.invoke(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ClientIntegrationTest {
|
|||
|
||||
return StdioClientTransport(
|
||||
socket.inputStream.asSource().buffered(),
|
||||
socket.outputStream.asSink().buffered()
|
||||
socket.outputStream.asSink().buffered(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -34,10 +34,8 @@ class ClientIntegrationTest {
|
|||
|
||||
val response: ListToolsResult = client.listTools()
|
||||
println(response.tools)
|
||||
|
||||
} finally {
|
||||
transport.close()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class StdioClientTransportTest : BaseTransportTest() {
|
|||
|
||||
val client = StdioClientTransport(
|
||||
input = input,
|
||||
output = output
|
||||
output = output,
|
||||
)
|
||||
|
||||
testClientOpenClose(client)
|
||||
|
|
@ -37,7 +37,7 @@ class StdioClientTransportTest : BaseTransportTest() {
|
|||
|
||||
val client = StdioClientTransport(
|
||||
input = input,
|
||||
output = output
|
||||
output = output,
|
||||
)
|
||||
|
||||
testClientRead(client)
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ class ServerTest {
|
|||
// Create server with tools capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
tools = ServerCapabilities.Tools(null)
|
||||
)
|
||||
tools = ServerCapabilities.Tools(null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Add a tool
|
||||
|
|
@ -66,12 +66,12 @@ class ServerTest {
|
|||
// Create server with tools capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
tools = ServerCapabilities.Tools(null)
|
||||
)
|
||||
tools = ServerCapabilities.Tools(null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Setup client
|
||||
|
|
@ -103,11 +103,11 @@ class ServerTest {
|
|||
fun `removeTool should throw when tools capability is not supported`() = runTest {
|
||||
// Create server without tools capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities()
|
||||
capabilities = ServerCapabilities(),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Verify that removing a tool throws an exception
|
||||
|
|
@ -122,12 +122,12 @@ class ServerTest {
|
|||
// Create server with tools capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
tools = ServerCapabilities.Tools(null)
|
||||
)
|
||||
tools = ServerCapabilities.Tools(null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Add tools
|
||||
|
|
@ -160,12 +160,12 @@ class ServerTest {
|
|||
// Create server with prompts capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
prompts = ServerCapabilities.Prompts(listChanged = false)
|
||||
)
|
||||
prompts = ServerCapabilities.Prompts(listChanged = false),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Add a prompt
|
||||
|
|
@ -173,7 +173,7 @@ class ServerTest {
|
|||
server.addPrompt(testPrompt) {
|
||||
GetPromptResult(
|
||||
description = "Test prompt description",
|
||||
messages = listOf()
|
||||
messages = listOf(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -199,12 +199,12 @@ class ServerTest {
|
|||
// Create server with prompts capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
prompts = ServerCapabilities.Prompts(listChanged = false)
|
||||
)
|
||||
prompts = ServerCapabilities.Prompts(listChanged = false),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Add prompts
|
||||
|
|
@ -213,13 +213,13 @@ class ServerTest {
|
|||
server.addPrompt(testPrompt1) {
|
||||
GetPromptResult(
|
||||
description = "Test prompt description 1",
|
||||
messages = listOf()
|
||||
messages = listOf(),
|
||||
)
|
||||
}
|
||||
server.addPrompt(testPrompt2) {
|
||||
GetPromptResult(
|
||||
description = "Test prompt description 2",
|
||||
messages = listOf()
|
||||
messages = listOf(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -245,12 +245,12 @@ class ServerTest {
|
|||
// Create server with resources capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(null, null)
|
||||
)
|
||||
resources = ServerCapabilities.Resources(null, null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Add a resource
|
||||
|
|
@ -259,7 +259,7 @@ class ServerTest {
|
|||
uri = testResourceUri,
|
||||
name = "Test Resource",
|
||||
description = "A test resource",
|
||||
mimeType = "text/plain"
|
||||
mimeType = "text/plain",
|
||||
) {
|
||||
ReadResourceResult(
|
||||
contents = listOf(
|
||||
|
|
@ -268,7 +268,7 @@ class ServerTest {
|
|||
uri = testResourceUri,
|
||||
mimeType = "text/plain",
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -294,12 +294,12 @@ class ServerTest {
|
|||
// Create server with resources capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(null, null)
|
||||
)
|
||||
resources = ServerCapabilities.Resources(null, null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Add resources
|
||||
|
|
@ -309,7 +309,7 @@ class ServerTest {
|
|||
uri = testResourceUri1,
|
||||
name = "Test Resource 1",
|
||||
description = "A test resource 1",
|
||||
mimeType = "text/plain"
|
||||
mimeType = "text/plain",
|
||||
) {
|
||||
ReadResourceResult(
|
||||
contents = listOf(
|
||||
|
|
@ -318,14 +318,14 @@ class ServerTest {
|
|||
uri = testResourceUri1,
|
||||
mimeType = "text/plain",
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
server.addResource(
|
||||
uri = testResourceUri2,
|
||||
name = "Test Resource 2",
|
||||
description = "A test resource 2",
|
||||
mimeType = "text/plain"
|
||||
mimeType = "text/plain",
|
||||
) {
|
||||
ReadResourceResult(
|
||||
contents = listOf(
|
||||
|
|
@ -334,7 +334,7 @@ class ServerTest {
|
|||
uri = testResourceUri2,
|
||||
mimeType = "text/plain",
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -360,12 +360,12 @@ class ServerTest {
|
|||
// Create server with prompts capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
prompts = ServerCapabilities.Prompts(listChanged = false)
|
||||
)
|
||||
prompts = ServerCapabilities.Prompts(listChanged = false),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Setup client
|
||||
|
|
@ -397,11 +397,11 @@ class ServerTest {
|
|||
fun `removePrompt should throw when prompts capability is not supported`() = runTest {
|
||||
// Create server without prompts capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities()
|
||||
capabilities = ServerCapabilities(),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Verify that removing a prompt throws an exception
|
||||
|
|
@ -416,12 +416,12 @@ class ServerTest {
|
|||
// Create server with resources capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities(
|
||||
resources = ServerCapabilities.Resources(null, null)
|
||||
)
|
||||
resources = ServerCapabilities.Resources(null, null),
|
||||
),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Setup client
|
||||
|
|
@ -432,7 +432,9 @@ class ServerTest {
|
|||
|
||||
// Track notifications
|
||||
var resourceListChangedNotificationReceived = false
|
||||
client.setNotificationHandler<ResourceListChangedNotification>(Method.Defined.NotificationsResourcesListChanged) {
|
||||
client.setNotificationHandler<ResourceListChangedNotification>(
|
||||
Method.Defined.NotificationsResourcesListChanged,
|
||||
) {
|
||||
resourceListChangedNotificationReceived = true
|
||||
CompletableDeferred(Unit)
|
||||
}
|
||||
|
|
@ -448,7 +450,7 @@ class ServerTest {
|
|||
assertFalse(result, "Removing non-existent resource should return false")
|
||||
assertFalse(
|
||||
resourceListChangedNotificationReceived,
|
||||
"No notification should be sent when resource doesn't exist"
|
||||
"No notification should be sent when resource doesn't exist",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -456,11 +458,11 @@ class ServerTest {
|
|||
fun `removeResource should throw when resources capability is not supported`() = runTest {
|
||||
// Create server without resources capability
|
||||
val serverOptions = ServerOptions(
|
||||
capabilities = ServerCapabilities()
|
||||
capabilities = ServerCapabilities(),
|
||||
)
|
||||
val server = Server(
|
||||
Implementation(name = "test server", version = "1.0"),
|
||||
serverOptions
|
||||
serverOptions,
|
||||
)
|
||||
|
||||
// Verify that removing a resource throws an exception
|
||||
|
|
|
|||
Loading…
Reference in a new issue