diff --git a/kotlin-sdk-client/api/kotlin-sdk-client.api b/kotlin-sdk-client/api/kotlin-sdk-client.api index 46a7b60d..fb785b9e 100644 --- a/kotlin-sdk-client/api/kotlin-sdk-client.api +++ b/kotlin-sdk-client/api/kotlin-sdk-client.api @@ -1,4 +1,18 @@ -public class io/modelcontextprotocol/kotlin/sdk/client/Client : io/modelcontextprotocol/kotlin/sdk/shared/Protocol { +public final class io/modelcontextprotocol/kotlin/sdk/client/ClientOptions : io/modelcontextprotocol/kotlin/sdk/shared/ProtocolOptions { + public fun ()V + public fun (Lio/modelcontextprotocol/kotlin/sdk/ClientCapabilities;Z)V + public synthetic fun (Lio/modelcontextprotocol/kotlin/sdk/ClientCapabilities;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getCapabilities ()Lio/modelcontextprotocol/kotlin/sdk/ClientCapabilities; +} + +public final class io/modelcontextprotocol/kotlin/sdk/client/KtorClientKt { + public static final fun mcpSse-BZiP2OM (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun mcpSse-BZiP2OM$default (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun mcpSseTransport-5_5nbZA (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;)Lio/modelcontextprotocol/kotlin/sdk/client/SseClientTransport; + public static synthetic fun mcpSseTransport-5_5nbZA$default (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/client/SseClientTransport; +} + +public class io/modelcontextprotocol/kotlin/sdk/client/McpClient : io/modelcontextprotocol/kotlin/sdk/shared/Protocol { public fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/client/ClientOptions;)V public synthetic fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/client/ClientOptions;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun addRoot (Ljava/lang/String;Ljava/lang/String;)V @@ -9,52 +23,38 @@ public class io/modelcontextprotocol/kotlin/sdk/client/Client : io/modelcontextp public fun assertRequestHandlerCapability (Lio/modelcontextprotocol/kotlin/sdk/Method;)V public final fun callTool (Lio/modelcontextprotocol/kotlin/sdk/CallToolRequest;ZLio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun callTool (Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;ZLio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun callTool$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/CallToolRequest;ZLio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static synthetic fun callTool$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;ZLio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun callTool$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/CallToolRequest;ZLio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun callTool$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;ZLio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun complete (Lio/modelcontextprotocol/kotlin/sdk/CompleteRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun complete$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/CompleteRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun complete$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/CompleteRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public fun connect (Lio/modelcontextprotocol/kotlin/sdk/shared/Transport;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getPrompt (Lio/modelcontextprotocol/kotlin/sdk/GetPromptRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun getPrompt$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/GetPromptRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun getPrompt$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/GetPromptRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun getServerCapabilities ()Lio/modelcontextprotocol/kotlin/sdk/ServerCapabilities; public final fun getServerInstructions ()Ljava/lang/String; public final fun getServerVersion ()Lio/modelcontextprotocol/kotlin/sdk/Implementation; public final fun listPrompts (Lio/modelcontextprotocol/kotlin/sdk/ListPromptsRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun listPrompts$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/ListPromptsRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun listPrompts$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/ListPromptsRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun listResourceTemplates (Lio/modelcontextprotocol/kotlin/sdk/ListResourceTemplatesRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun listResourceTemplates$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/ListResourceTemplatesRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun listResourceTemplates$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/ListResourceTemplatesRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun listResources (Lio/modelcontextprotocol/kotlin/sdk/ListResourcesRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun listResources$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/ListResourcesRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun listResources$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/ListResourcesRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun listTools (Lio/modelcontextprotocol/kotlin/sdk/ListToolsRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun listTools$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/ListToolsRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun listTools$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/ListToolsRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun ping (Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun ping$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun ping$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun readResource (Lio/modelcontextprotocol/kotlin/sdk/ReadResourceRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun readResource$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/ReadResourceRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun readResource$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/ReadResourceRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun removeRoot (Ljava/lang/String;)Z public final fun removeRoots (Ljava/util/List;)I public final fun sendRootsListChanged (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun setElicitationHandler (Lkotlin/jvm/functions/Function1;)V public final fun setLoggingLevel (Lio/modelcontextprotocol/kotlin/sdk/LoggingLevel;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun setLoggingLevel$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/LoggingLevel;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun setLoggingLevel$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/LoggingLevel;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun subscribeResource (Lio/modelcontextprotocol/kotlin/sdk/SubscribeRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun subscribeResource$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/SubscribeRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun subscribeResource$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/SubscribeRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun unsubscribeResource (Lio/modelcontextprotocol/kotlin/sdk/UnsubscribeRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun unsubscribeResource$default (Lio/modelcontextprotocol/kotlin/sdk/client/Client;Lio/modelcontextprotocol/kotlin/sdk/UnsubscribeRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; -} - -public final class io/modelcontextprotocol/kotlin/sdk/client/ClientOptions : io/modelcontextprotocol/kotlin/sdk/shared/ProtocolOptions { - public fun ()V - public fun (Lio/modelcontextprotocol/kotlin/sdk/ClientCapabilities;Z)V - public synthetic fun (Lio/modelcontextprotocol/kotlin/sdk/ClientCapabilities;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun getCapabilities ()Lio/modelcontextprotocol/kotlin/sdk/ClientCapabilities; -} - -public final class io/modelcontextprotocol/kotlin/sdk/client/KtorClientKt { - public static final fun mcpSse-BZiP2OM (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun mcpSse-BZiP2OM$default (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun mcpSseTransport-5_5nbZA (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;)Lio/modelcontextprotocol/kotlin/sdk/client/SseClientTransport; - public static synthetic fun mcpSseTransport-5_5nbZA$default (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/time/Duration;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/client/SseClientTransport; + public static synthetic fun unsubscribeResource$default (Lio/modelcontextprotocol/kotlin/sdk/client/McpClient;Lio/modelcontextprotocol/kotlin/sdk/UnsubscribeRequest;Lio/modelcontextprotocol/kotlin/sdk/shared/RequestOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } public final class io/modelcontextprotocol/kotlin/sdk/client/SseClientTransport : io/modelcontextprotocol/kotlin/sdk/shared/AbstractTransport { diff --git a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/KtorClient.kt b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/KtorClient.kt index ccc1496e..df2a92f7 100644 --- a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/KtorClient.kt +++ b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/KtorClient.kt @@ -27,15 +27,15 @@ public fun HttpClient.mcpSseTransport( * @param urlString Optional URL of the MCP server. * @param reconnectionTime Optional duration to wait before attempting to reconnect. * @param requestBuilder Optional lambda to configure the HTTP request. - * @return A connected [Client] ready for MCP communication. + * @return A connected [McpClient] ready for MCP communication. */ public suspend fun HttpClient.mcpSse( urlString: String? = null, reconnectionTime: Duration? = null, requestBuilder: HttpRequestBuilder.() -> Unit = {}, -): Client { +): McpClient { val transport = mcpSseTransport(urlString, reconnectionTime, requestBuilder) - val client = Client( + val client = McpClient( Implementation( name = IMPLEMENTATION_NAME, version = LIB_VERSION, diff --git a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/Client.kt b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/McpClient.kt similarity index 99% rename from kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/Client.kt rename to kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/McpClient.kt index 56fd1caf..a495325c 100644 --- a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/Client.kt +++ b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/McpClient.kt @@ -62,6 +62,9 @@ import kotlin.coroutines.cancellation.CancellationException private val logger = KotlinLogging.logger {} +@Deprecated("Use McpClient", ReplaceWith("McpClient"), DeprecationLevel.WARNING) +public typealias Client = McpClient + /** * Options for configuring the MCP client. * @@ -84,7 +87,7 @@ public class ClientOptions( * @param clientInfo Information about the client implementation (name, version). * @param options Configuration options for this client. */ -public open class Client(private val clientInfo: Implementation, options: ClientOptions = ClientOptions()) : +public open class McpClient(private val clientInfo: Implementation, options: ClientOptions = ClientOptions()) : Protocol(options) { /** diff --git a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpMcpKtorClientExtensions.kt b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpMcpKtorClientExtensions.kt index 1a600a3a..7db9dcb3 100644 --- a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpMcpKtorClientExtensions.kt +++ b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpMcpKtorClientExtensions.kt @@ -28,15 +28,15 @@ public fun HttpClient.mcpStreamableHttpTransport( * @param url URL of the MCP server. * @param reconnectionTime Optional duration to wait before attempting to reconnect. * @param requestBuilder Optional lambda to configure the HTTP request. - * @return A connected [Client] ready for MCP communication. + * @return A connected [McpClient] ready for MCP communication. */ public suspend fun HttpClient.mcpStreamableHttp( url: String, reconnectionTime: Duration? = null, requestBuilder: HttpRequestBuilder.() -> Unit = {}, -): Client { +): McpClient { val transport = mcpStreamableHttpTransport(url, reconnectionTime, requestBuilder) - val client = Client(Implementation(name = IMPLEMENTATION_NAME, version = LIB_VERSION)) + val client = McpClient(Implementation(name = IMPLEMENTATION_NAME, version = LIB_VERSION)) client.connect(transport) return client } diff --git a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/WebSocketMcpKtorClientExtensions.kt b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/WebSocketMcpKtorClientExtensions.kt index 86479533..f2030512 100644 --- a/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/WebSocketMcpKtorClientExtensions.kt +++ b/kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/WebSocketMcpKtorClientExtensions.kt @@ -26,14 +26,14 @@ public fun HttpClient.mcpWebSocketTransport( * * @param urlString Optional URL of the MCP server. * @param requestBuilder Optional lambda to configure the HTTP request. - * @return A connected [Client] ready for MCP communication. + * @return A connected [McpClient] ready for MCP communication. */ public suspend fun HttpClient.mcpWebSocket( urlString: String? = null, requestBuilder: HttpRequestBuilder.() -> Unit = {}, -): Client { +): McpClient { val transport = mcpWebSocketTransport(urlString, requestBuilder) - val client = Client( + val client = McpClient( Implementation( name = IMPLEMENTATION_NAME, version = LIB_VERSION, diff --git a/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientMetaParameterTest.kt b/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientMetaParameterTest.kt index e7061073..a48a4f93 100644 --- a/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientMetaParameterTest.kt +++ b/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientMetaParameterTest.kt @@ -25,14 +25,14 @@ import kotlin.test.assertTrue */ class ClientMetaParameterTest { - private lateinit var client: Client + private lateinit var client: McpClient private lateinit var mockTransport: MockTransport private val clientInfo = Implementation("test-client", "1.0.0") @BeforeTest fun setup() = runTest { mockTransport = MockTransport() - client = Client(clientInfo = clientInfo) + client = McpClient(clientInfo = clientInfo) mockTransport.setupInitializationResponse() client.connect(mockTransport) } diff --git a/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransportTest.kt b/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransportTest.kt index a72bd853..7b31b9fc 100644 --- a/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransportTest.kt +++ b/kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransportTest.kt @@ -397,7 +397,7 @@ class StreamableHttpClientTransportTest { ) } - val client = Client( + val client = McpClient( clientInfo = Implementation( name = "test-client", version = "1.0", diff --git a/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/AbstractStreamableHttpClientTest.kt b/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/AbstractStreamableHttpClientTest.kt index 77ba553e..28385ea7 100644 --- a/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/AbstractStreamableHttpClientTest.kt +++ b/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/AbstractStreamableHttpClientTest.kt @@ -19,7 +19,7 @@ internal abstract class AbstractStreamableHttpClientTest { mockMcp.checkForUnmatchedRequests() } - protected suspend fun connect(client: Client) { + protected suspend fun connect(client: McpClient) { client.connect( StreamableHttpClientTransport( url = mockMcp.url, diff --git a/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTest.kt b/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTest.kt index 1e5ca7ee..68e947d3 100644 --- a/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTest.kt +++ b/kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTest.kt @@ -34,7 +34,7 @@ internal class StreamableHttpClientTest : AbstractStreamableHttpClientTest() { @Test fun `test streamableHttpClient`() = runBlocking { - val client = Client( + val client = McpClient( clientInfo = Implementation( name = "client1", version = "1.0.0", @@ -173,7 +173,7 @@ internal class StreamableHttpClientTest : AbstractStreamableHttpClientTest() { private suspend fun checkSupportNonStreamingResponse(contentType: ContentType, statusCode: HttpStatusCode) { val sessionId = "SID_${Uuid.random().toHexString()}" val clientName = "client-${Uuid.random().toHexString()}" - val client = Client( + val client = McpClient( clientInfo = Implementation(name = clientName, version = "1.0.0"), options = ClientOptions( capabilities = ClientCapabilities(), diff --git a/kotlin-sdk-server/api/kotlin-sdk-server.api b/kotlin-sdk-server/api/kotlin-sdk-server.api index 8ee5af28..ed228cd6 100644 --- a/kotlin-sdk-server/api/kotlin-sdk-server.api +++ b/kotlin-sdk-server/api/kotlin-sdk-server.api @@ -5,6 +5,41 @@ public final class io/modelcontextprotocol/kotlin/sdk/server/KtorServerKt { public static final fun mcp (Lio/ktor/server/routing/Routing;Lkotlin/jvm/functions/Function1;)V } +public class io/modelcontextprotocol/kotlin/sdk/server/McpServer { + public fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun addPrompt (Lio/modelcontextprotocol/kotlin/sdk/Prompt;Lkotlin/jvm/functions/Function2;)V + public final fun addPrompt (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function2;)V + public static synthetic fun addPrompt$default (Lio/modelcontextprotocol/kotlin/sdk/server/McpServer;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V + public final fun addPrompts (Ljava/util/List;)V + public final fun addResource (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V + public static synthetic fun addResource$default (Lio/modelcontextprotocol/kotlin/sdk/server/McpServer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V + public final fun addResources (Ljava/util/List;)V + public final fun addTool (Lio/modelcontextprotocol/kotlin/sdk/Tool;Lkotlin/jvm/functions/Function2;)V + public final fun addTool (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/ToolAnnotations;Lkotlin/jvm/functions/Function2;)V + public static synthetic fun addTool$default (Lio/modelcontextprotocol/kotlin/sdk/server/McpServer;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/ToolAnnotations;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V + public final fun addTools (Ljava/util/List;)V + public final fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun connect (Lio/modelcontextprotocol/kotlin/sdk/shared/Transport;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + protected final fun getInstructionsProvider ()Lkotlin/jvm/functions/Function0; + protected final fun getOptions ()Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions; + public final fun getPrompts ()Ljava/util/Map; + public final fun getResources ()Ljava/util/Map; + protected final fun getServerInfo ()Lio/modelcontextprotocol/kotlin/sdk/Implementation; + public final fun getTools ()Ljava/util/Map; + public final fun onClose (Lkotlin/jvm/functions/Function0;)V + public final fun onConnect (Lkotlin/jvm/functions/Function0;)V + public final fun onInitialized (Lkotlin/jvm/functions/Function0;)V + public final fun removePrompt (Ljava/lang/String;)Z + public final fun removePrompts (Ljava/util/List;)I + public final fun removeResource (Ljava/lang/String;)Z + public final fun removeResources (Ljava/util/List;)I + public final fun removeTool (Ljava/lang/String;)Z + public final fun removeTools (Ljava/util/List;)I +} + public final class io/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt { public fun (Lio/modelcontextprotocol/kotlin/sdk/Prompt;Lkotlin/jvm/functions/Function2;)V public final fun component1 ()Lio/modelcontextprotocol/kotlin/sdk/Prompt; @@ -44,40 +79,6 @@ public final class io/modelcontextprotocol/kotlin/sdk/server/RegisteredTool { public fun toString ()Ljava/lang/String; } -public class io/modelcontextprotocol/kotlin/sdk/server/Server { - public fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;Ljava/lang/String;)V - public fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;Lkotlin/jvm/functions/Function0;)V - public synthetic fun (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun addPrompt (Lio/modelcontextprotocol/kotlin/sdk/Prompt;Lkotlin/jvm/functions/Function2;)V - public final fun addPrompt (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function2;)V - public static synthetic fun addPrompt$default (Lio/modelcontextprotocol/kotlin/sdk/server/Server;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V - public final fun addPrompts (Ljava/util/List;)V - public final fun addResource (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V - public static synthetic fun addResource$default (Lio/modelcontextprotocol/kotlin/sdk/server/Server;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V - public final fun addResources (Ljava/util/List;)V - public final fun addTool (Lio/modelcontextprotocol/kotlin/sdk/Tool;Lkotlin/jvm/functions/Function2;)V - public final fun addTool (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/ToolAnnotations;Lkotlin/jvm/functions/Function2;)V - public static synthetic fun addTool$default (Lio/modelcontextprotocol/kotlin/sdk/server/Server;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/ToolAnnotations;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V - public final fun addTools (Ljava/util/List;)V - public final fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun connect (Lio/modelcontextprotocol/kotlin/sdk/shared/Transport;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - protected final fun getInstructionsProvider ()Lkotlin/jvm/functions/Function0; - protected final fun getOptions ()Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions; - public final fun getPrompts ()Ljava/util/Map; - public final fun getResources ()Ljava/util/Map; - protected final fun getServerInfo ()Lio/modelcontextprotocol/kotlin/sdk/Implementation; - public final fun getTools ()Ljava/util/Map; - public final fun onClose (Lkotlin/jvm/functions/Function0;)V - public final fun onConnect (Lkotlin/jvm/functions/Function0;)V - public final fun onInitialized (Lkotlin/jvm/functions/Function0;)V - public final fun removePrompt (Ljava/lang/String;)Z - public final fun removePrompts (Ljava/util/List;)I - public final fun removeResource (Ljava/lang/String;)Z - public final fun removeResources (Ljava/util/List;)I - public final fun removeTool (Ljava/lang/String;)Z - public final fun removeTools (Ljava/util/List;)I -} - public final class io/modelcontextprotocol/kotlin/sdk/server/ServerOptions : io/modelcontextprotocol/kotlin/sdk/shared/ProtocolOptions { public fun (Lio/modelcontextprotocol/kotlin/sdk/ServerCapabilities;Z)V public synthetic fun (Lio/modelcontextprotocol/kotlin/sdk/ServerCapabilities;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V diff --git a/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorServer.kt b/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorServer.kt index 934ba049..fe3b6da7 100644 --- a/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorServer.kt +++ b/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorServer.kt @@ -37,7 +37,7 @@ internal class SseTransportManager(transports: Map = } @KtorDsl -public fun Routing.mcp(path: String, block: ServerSSESession.() -> Server) { +public fun Routing.mcp(path: String, block: ServerSSESession.() -> McpServer) { route(path) { mcp(block) } @@ -47,7 +47,7 @@ public fun Routing.mcp(path: String, block: ServerSSESession.() -> Server) { * Configures the Ktor Application to handle Model Context Protocol (MCP) over Server-Sent Events (SSE). */ @KtorDsl -public fun Routing.mcp(block: ServerSSESession.() -> Server) { +public fun Routing.mcp(block: ServerSSESession.() -> McpServer) { val sseTransportManager = SseTransportManager() sse { @@ -61,12 +61,12 @@ public fun Routing.mcp(block: ServerSSESession.() -> Server) { @Suppress("FunctionName") @Deprecated("Use mcp() instead", ReplaceWith("mcp(block)"), DeprecationLevel.ERROR) -public fun Application.MCP(block: ServerSSESession.() -> Server) { +public fun Application.MCP(block: ServerSSESession.() -> McpServer) { mcp(block) } @KtorDsl -public fun Application.mcp(block: ServerSSESession.() -> Server) { +public fun Application.mcp(block: ServerSSESession.() -> McpServer) { install(SSE) routing { @@ -77,7 +77,7 @@ public fun Application.mcp(block: ServerSSESession.() -> Server) { internal suspend fun ServerSSESession.mcpSseEndpoint( postEndpoint: String, sseTransportManager: SseTransportManager, - block: ServerSSESession.() -> Server, + block: ServerSSESession.() -> McpServer, ) { val transport = mcpSseTransport(postEndpoint, sseTransportManager) diff --git a/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/Server.kt b/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/McpServer.kt similarity index 97% rename from kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/Server.kt rename to kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/McpServer.kt index 8c010560..16eb5ee9 100644 --- a/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/Server.kt +++ b/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/McpServer.kt @@ -37,6 +37,9 @@ import kotlinx.coroutines.CancellationException private val logger = KotlinLogging.logger {} +@Deprecated("Use McpServer", ReplaceWith("McpServer"), DeprecationLevel.WARNING) +public typealias Server = McpServer + /** * Configuration options for the MCP server. * @@ -57,12 +60,14 @@ public class ServerOptions(public val capabilities: ServerCapabilities, enforceS * @param options Configuration options for the server. * @param instructionsProvider Optional provider for instructions from the server to the client about how to use * this server. The provider is called each time a new session is started to support dynamic instructions. + * @param configurer Lambda to configure mcp server. */ -public open class Server( +public open class McpServer( protected val serverInfo: Implementation, protected val options: ServerOptions, protected val instructionsProvider: (() -> String)? = null, + configurer: McpServer.() -> Unit = {}, ) { /** * Alternative constructor that provides the instructions directly as a string. @@ -70,12 +75,19 @@ public open class Server( * @param serverInfo Information about this server implementation (name, version). * @param options Configuration options for the server. * @param instructions Instructions from the server to the client about how to use this server. + * @param configurer Lambda to configure mcp server. */ public constructor( serverInfo: Implementation, options: ServerOptions, instructions: String, - ) : this(serverInfo, options, { instructions }) + configurer: McpServer.() -> Unit = {}, + ) : this( + serverInfo = serverInfo, + options = options, + instructionsProvider = { instructions }, + configurer = configurer, + ) private val sessions = atomic(persistentListOf()) @@ -98,6 +110,10 @@ public open class Server( public val resources: Map get() = _resources.value + init { + configurer(this) + } + public suspend fun close() { logger.debug { "Closing MCP server" } sessions.value.forEach { it.close() } @@ -148,6 +164,7 @@ public open class Server( } logger.debug { "Server session connecting to transport" } + session.connect(transport) logger.debug { "Server session successfully connected to transport" } sessions.update { it.add(session) } diff --git a/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/WebSocketMcpKtorServerExtensions.kt b/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/WebSocketMcpKtorServerExtensions.kt index 1ceb764b..178bac60 100644 --- a/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/WebSocketMcpKtorServerExtensions.kt +++ b/kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/WebSocketMcpKtorServerExtensions.kt @@ -23,7 +23,7 @@ private val logger = KotlinLogging.logger {} * Configures the Ktor Application to handle Model Context Protocol (MCP) over WebSocket. */ @KtorDsl -public fun Routing.mcpWebSocket(block: () -> Server) { +public fun Routing.mcpWebSocket(block: () -> McpServer) { webSocket { mcpWebSocketEndpoint(block) } @@ -33,7 +33,7 @@ public fun Routing.mcpWebSocket(block: () -> Server) { * Configures the Ktor Application to handle Model Context Protocol (MCP) over WebSocket. */ @KtorDsl -public fun Routing.mcpWebSocket(path: String, block: () -> Server) { +public fun Routing.mcpWebSocket(path: String, block: () -> McpServer) { webSocket(path) { mcpWebSocketEndpoint(block) } @@ -43,7 +43,7 @@ public fun Routing.mcpWebSocket(path: String, block: () -> Server) { * Configures the Ktor Application to handle Model Context Protocol (MCP) over WebSocket. */ @KtorDsl -public fun Application.mcpWebSocket(block: () -> Server) { +public fun Application.mcpWebSocket(block: () -> McpServer) { install(WebSockets) routing { @@ -55,7 +55,7 @@ public fun Application.mcpWebSocket(block: () -> Server) { * Configures the Ktor Application to handle Model Context Protocol (MCP) over WebSocket at the specified path. */ @KtorDsl -public fun Application.mcpWebSocket(path: String, block: () -> Server) { +public fun Application.mcpWebSocket(path: String, block: () -> McpServer) { install(WebSockets) routing { @@ -63,7 +63,7 @@ public fun Application.mcpWebSocket(path: String, block: () -> Server) { } } -internal suspend fun WebSocketServerSession.mcpWebSocketEndpoint(block: () -> Server) { +internal suspend fun WebSocketServerSession.mcpWebSocketEndpoint(block: () -> McpServer) { logger.info { "Ktor Server establishing new connection" } val transport = createMcpTransport(this) val server = block() @@ -90,7 +90,7 @@ private fun createMcpTransport(webSocketSession: WebSocketServerSession): WebSoc ReplaceWith("Routing.mcpWebSocket"), DeprecationLevel.WARNING, ) -public fun Route.mcpWebSocket(options: ServerOptions? = null, handler: suspend Server.() -> Unit = {}) { +public fun Route.mcpWebSocket(options: ServerOptions? = null, handler: suspend McpServer.() -> Unit = {}) { webSocket { createMcpServer(this, options, handler) } @@ -101,7 +101,7 @@ public fun Route.mcpWebSocket(options: ServerOptions? = null, handler: suspend S ReplaceWith("Routing.mcpWebSocket"), DeprecationLevel.WARNING, ) -public fun Route.mcpWebSocket(block: () -> Server) { +public fun Route.mcpWebSocket(block: () -> McpServer) { webSocket { block().connect(createMcpTransport(this)) } @@ -119,7 +119,11 @@ public fun Route.mcpWebSocket(block: () -> Server) { ReplaceWith("Routing.mcpWebSocket"), DeprecationLevel.WARNING, ) -public fun Route.mcpWebSocket(path: String, options: ServerOptions? = null, handler: suspend Server.() -> Unit = {}) { +public fun Route.mcpWebSocket( + path: String, + options: ServerOptions? = null, + handler: suspend McpServer.() -> Unit = {}, +) { webSocket(path) { createMcpServer(this, options, handler) } @@ -172,11 +176,11 @@ public fun Route.mcpWebSocketTransport(path: String, handler: suspend WebSocketM private suspend fun Route.createMcpServer( session: WebSocketServerSession, options: ServerOptions?, - handler: suspend Server.() -> Unit, + handler: suspend McpServer.() -> Unit, ) { val transport = createMcpTransport(session) - val server = Server( + val server = McpServer( serverInfo = Implementation( name = IMPLEMENTATION_NAME, version = LIB_VERSION, diff --git a/kotlin-sdk-test/build.gradle.kts b/kotlin-sdk-test/build.gradle.kts index c7f8b60d..41bf5458 100644 --- a/kotlin-sdk-test/build.gradle.kts +++ b/kotlin-sdk-test/build.gradle.kts @@ -24,7 +24,6 @@ kotlin { } jvmTest { dependencies { - implementation(kotlin("test-junit5")) implementation(libs.awaitility) runtimeOnly(libs.slf4j.simple) } diff --git a/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientTest.kt b/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientTest.kt index d132ae5f..ea17df00 100644 --- a/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientTest.kt +++ b/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientTest.kt @@ -28,7 +28,7 @@ import io.modelcontextprotocol.kotlin.sdk.SUPPORTED_PROTOCOL_VERSIONS import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities import io.modelcontextprotocol.kotlin.sdk.TextContent import io.modelcontextprotocol.kotlin.sdk.Tool -import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.McpServer import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions import io.modelcontextprotocol.kotlin.sdk.server.ServerSession import io.modelcontextprotocol.kotlin.sdk.shared.AbstractTransport @@ -83,7 +83,7 @@ class ClientTest { } } - val client = Client( + val client = McpClient( clientInfo = Implementation( name = "test client", version = "1.0", @@ -129,7 +129,7 @@ class ClientTest { } } - val client = Client( + val client = McpClient( clientInfo = Implementation( name = "test client", version = "1.0", @@ -180,7 +180,7 @@ class ClientTest { } } - val client = Client( + val client = McpClient( clientInfo = Implementation( name = "test client", version = "1.0", @@ -212,7 +212,7 @@ class ClientTest { } } - val client = Client( + val client = McpClient( clientInfo = Implementation( name = "test client", version = "1.0", @@ -237,14 +237,14 @@ class ClientTest { tools = ServerCapabilities.Tools(null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), options = ClientOptions( capabilities = ClientCapabilities(sampling = EmptyJsonObject), @@ -300,12 +300,12 @@ class ClientTest { @Test fun `should respect client notification capabilities`() = runTest { - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), ServerOptions(capabilities = ServerCapabilities()), ) - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), options = ClientOptions( capabilities = ClientCapabilities( @@ -331,7 +331,7 @@ class ClientTest { client.sendRootsListChanged() // Create a new client without the roots.listChanged capability - val clientWithoutCapability = Client( + val clientWithoutCapability = McpClient( clientInfo = Implementation(name = "test client without capability", version = "1.0"), options = ClientOptions( capabilities = ClientCapabilities(), @@ -352,7 +352,7 @@ class ClientTest { @Test fun `should respect server notification capabilities`() = runTest { - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), ServerOptions( capabilities = ServerCapabilities( @@ -362,7 +362,7 @@ class ClientTest { ), ) - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), options = ClientOptions( capabilities = ClientCapabilities(), @@ -410,7 +410,7 @@ class ClientTest { @Test fun `should handle client cancelling a request`() = runTest { - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), ServerOptions( capabilities = ServerCapabilities( @@ -426,7 +426,7 @@ class ClientTest { val defTimeOut = CompletableDeferred() val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), options = ClientOptions(capabilities = ClientCapabilities()), ) @@ -476,7 +476,7 @@ class ClientTest { @Test fun `should handle request timeout`() = runTest { - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), ServerOptions( capabilities = ServerCapabilities( @@ -489,7 +489,7 @@ class ClientTest { ) val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), options = ClientOptions(capabilities = ClientCapabilities()), ) @@ -533,7 +533,7 @@ class ClientTest { @Test fun `should only allow setRequestHandler for declared capabilities`() = runTest { - val client = Client( + val client = McpClient( clientInfo = Implementation( name = "test client", version = "1.0", @@ -567,14 +567,14 @@ class ClientTest { tools = ServerCapabilities.Tools(null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), options = ClientOptions( capabilities = ClientCapabilities(sampling = EmptyJsonObject), @@ -648,7 +648,7 @@ class ClientTest { @Test fun `listRoots returns list of roots`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities( @@ -665,7 +665,7 @@ class ClientTest { val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val server = Server( + val server = McpServer( serverInfo = Implementation(name = "test server", version = "1.0"), options = ServerOptions( capabilities = ServerCapabilities(), @@ -697,7 +697,7 @@ class ClientTest { @Test fun `addRoot should throw when roots capability is not supported`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities(), @@ -713,7 +713,7 @@ class ClientTest { @Test fun `removeRoot should throw when roots capability is not supported`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities(), @@ -729,7 +729,7 @@ class ClientTest { @Test fun `removeRoot should remove a root`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities( @@ -755,7 +755,7 @@ class ClientTest { @Test fun `removeRoots should remove multiple roots`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities( @@ -783,7 +783,7 @@ class ClientTest { @Test fun `sendRootsListChanged should notify server`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities( @@ -794,7 +794,7 @@ class ClientTest { val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val server = Server( + val server = McpServer( serverInfo = Implementation(name = "test server", version = "1.0"), options = ServerOptions( capabilities = ServerCapabilities(), @@ -835,7 +835,7 @@ class ClientTest { @Test fun `should reject server elicitation when elicitation capability is not supported`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities(), @@ -844,7 +844,7 @@ class ClientTest { val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val server = Server( + val server = McpServer( serverInfo = Implementation(name = "test server", version = "1.0"), options = ServerOptions( capabilities = ServerCapabilities(), @@ -888,7 +888,7 @@ class ClientTest { @Test fun `should handle server elicitation`() = runTest { - val client = Client( + val client = McpClient( Implementation(name = "test client", version = "1.0"), ClientOptions( capabilities = ClientCapabilities( @@ -924,7 +924,7 @@ class ClientTest { val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val server = Server( + val server = McpServer( serverInfo = Implementation(name = "test server", version = "1.0"), options = ServerOptions( capabilities = ServerCapabilities(), diff --git a/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/SseTransportTest.kt b/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/SseTransportTest.kt index fa4ae020..d47000f4 100644 --- a/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/SseTransportTest.kt +++ b/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/SseTransportTest.kt @@ -8,7 +8,7 @@ import io.ktor.server.engine.embeddedServer import io.ktor.server.routing.routing import io.modelcontextprotocol.kotlin.sdk.Implementation import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities -import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.McpServer import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions import io.modelcontextprotocol.kotlin.sdk.server.mcp import io.modelcontextprotocol.kotlin.sdk.shared.BaseTransportTest @@ -23,11 +23,11 @@ class SseTransportTest : BaseTransportTest() { private suspend fun EmbeddedServer<*, *>.actualPort() = engine.resolvedConnectors().first().port - private lateinit var mcpServer: Server + private lateinit var mcpServer: McpServer @BeforeTest fun setUp() { - mcpServer = Server( + mcpServer = McpServer( serverInfo = Implementation( name = "test-server", version = "1.0", diff --git a/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/SseIntegrationTest.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/SseIntegrationTest.kt similarity index 80% rename from kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/SseIntegrationTest.kt rename to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/SseIntegrationTest.kt index 29718128..7af1069f 100644 --- a/kotlin-sdk-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/SseIntegrationTest.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/SseIntegrationTest.kt @@ -15,15 +15,14 @@ import io.modelcontextprotocol.kotlin.sdk.PromptMessage import io.modelcontextprotocol.kotlin.sdk.Role import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities import io.modelcontextprotocol.kotlin.sdk.TextContent -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.client.mcpSseTransport -import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.McpServer import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions import io.modelcontextprotocol.kotlin.sdk.server.mcp import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext -import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertTrue import kotlin.time.Duration.Companion.seconds @@ -33,15 +32,14 @@ import io.ktor.server.sse.SSE as ServerSSE class SseIntegrationTest { @Test - @Ignore // Ignored because it doesn’t work with wasm/js in Ktor 3.2.3 fun `client should be able to connect to sse server`() = runTest(timeout = 5.seconds) { var server: EmbeddedServer? = null - var client: Client? = null + var client: McpClient? = null try { withContext(Dispatchers.Default) { server = initServer() - val port = server.engine.resolvedConnectors().first().port + val port = server.engine.resolvedConnectors().single().port client = initClient(serverPort = port) } } finally { @@ -58,10 +56,9 @@ class SseIntegrationTest { * 3. Observe that Client A receives a response related to it. */ @Test - @Ignore // Ignored because it doesn’t work with wasm/js in Ktor 3.2.3 fun `single sse connection`() = runTest(timeout = 5.seconds) { var server: EmbeddedServer? = null - var client: Client? = null + var client: McpClient? = null try { withContext(Dispatchers.Default) { server = initServer() @@ -86,11 +83,10 @@ class SseIntegrationTest { * 4. Observe that Client B (connection #2) receives a response related to sessionId#1. */ @Test - @Ignore // Ignored because it doesn’t work with wasm/js in Ktor 3.2.3 fun `multiple sse connections`() = runTest(timeout = 5.seconds) { var server: EmbeddedServer? = null - var clientA: Client? = null - var clientB: Client? = null + var clientA: McpClient? = null + var clientB: McpClient? = null try { withContext(Dispatchers.Default) { @@ -115,8 +111,8 @@ class SseIntegrationTest { } } - private suspend fun initClient(name: String = "", serverPort: Int): Client { - val client = Client( + private suspend fun initClient(name: String = "", serverPort: Int): McpClient { + val client = McpClient( Implementation(name = name, version = "1.0.0"), ) @@ -138,39 +134,39 @@ class SseIntegrationTest { } private suspend fun initServer(): EmbeddedServer { - val server = Server( + val mcpServer = McpServer( Implementation(name = "sse-server", version = "1.0.0"), ServerOptions( capabilities = ServerCapabilities(prompts = ServerCapabilities.Prompts(listChanged = true)), ), - ) - - server.addPrompt( - name = "prompt", - description = "Prompt description", - arguments = listOf( - PromptArgument( - name = "client", - description = "Client name who requested a prompt", - required = true, - ), - ), - ) { request -> - GetPromptResult( - "Prompt for ${request.name}", - messages = listOf( - PromptMessage( - role = Role.user, - content = TextContent("Prompt for client ${request.arguments?.get("client")}"), + ) { + addPrompt( + name = "prompt", + description = "Prompt description", + arguments = listOf( + PromptArgument( + name = "client", + description = "Client name who requested a prompt", + required = true, ), ), - ) + ) { request -> + GetPromptResult( + "Prompt for ${request.name}", + messages = listOf( + PromptMessage( + role = Role.user, + content = TextContent("Prompt for client ${request.arguments?.get("client")}"), + ), + ), + ) + } } val ktorServer = embeddedServer(ServerCIO, host = URL, port = PORT) { install(ServerSSE) routing { - mcp { server } + mcp { mcpServer } } } @@ -180,7 +176,7 @@ class SseIntegrationTest { /** * Retrieves a prompt result using the provided client and client name. */ - private suspend fun getPrompt(client: Client, clientName: String): String { + private suspend fun getPrompt(client: McpClient, clientName: String): String { val response = client.getPrompt( GetPromptRequest( "prompt", diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/KotlinTestBase.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/KotlinTestBase.kt index 563fa853..4608beaf 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/KotlinTestBase.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/KotlinTestBase.kt @@ -9,11 +9,11 @@ import io.ktor.server.engine.embeddedServer import io.ktor.server.routing.routing import io.modelcontextprotocol.kotlin.sdk.Implementation import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.client.SseClientTransport import io.modelcontextprotocol.kotlin.sdk.client.StdioClientTransport import io.modelcontextprotocol.kotlin.sdk.integration.utils.Retry -import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.McpServer import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport import io.modelcontextprotocol.kotlin.sdk.server.mcp @@ -39,8 +39,8 @@ abstract class KotlinTestBase { protected val host = "localhost" protected var port: Int = 0 - protected lateinit var server: Server - protected lateinit var client: Client + protected lateinit var server: McpServer + protected lateinit var client: McpClient protected lateinit var serverEngine: EmbeddedServer<*, *> // Transport selection @@ -80,7 +80,7 @@ abstract class KotlinTestBase { }, "http://$host:$port", ) - client = Client( + client = McpClient( Implementation("test", "1.0"), ) client.connect(transport) @@ -93,7 +93,7 @@ abstract class KotlinTestBase { input = input, output = output, ) - client = Client( + client = McpClient( Implementation("test", "1.0"), ) client.connect(transport) @@ -104,7 +104,7 @@ abstract class KotlinTestBase { protected fun setupServer() { val capabilities = configureServerCapabilities() - server = Server( + server = McpServer( Implementation(name = "test-server", version = "1.0"), ServerOptions(capabilities = capabilities), ) diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/websocket/WebSocketIntegrationTest.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/websocket/WebSocketIntegrationTest.kt index 6200e083..987f126e 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/websocket/WebSocketIntegrationTest.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/websocket/WebSocketIntegrationTest.kt @@ -14,9 +14,9 @@ import io.modelcontextprotocol.kotlin.sdk.PromptMessage import io.modelcontextprotocol.kotlin.sdk.Role import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities import io.modelcontextprotocol.kotlin.sdk.TextContent -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.client.mcpWebSocketTransport -import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.McpServer import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions import io.modelcontextprotocol.kotlin.sdk.server.mcpWebSocket import kotlinx.coroutines.Dispatchers @@ -35,7 +35,7 @@ class WebSocketIntegrationTest { @Test fun `client should be able to connect to websocket server 2`() = runTest(timeout = 5.seconds) { var server: EmbeddedServer? = null - var client: Client? = null + var client: McpClient? = null try { withContext(Dispatchers.Default) { @@ -59,7 +59,7 @@ class WebSocketIntegrationTest { @Test fun `single websocket connection`() = runTest(timeout = 5.seconds) { var server: EmbeddedServer? = null - var client: Client? = null + var client: McpClient? = null try { withContext(Dispatchers.Default) { @@ -87,8 +87,8 @@ class WebSocketIntegrationTest { @Test fun `multiple websocket connections`() = runTest(timeout = 5.seconds) { var server: EmbeddedServer? = null - var clientA: Client? = null - var clientB: Client? = null + var clientA: McpClient? = null + var clientB: McpClient? = null try { withContext(Dispatchers.Default) { @@ -112,8 +112,8 @@ class WebSocketIntegrationTest { } } - private suspend fun initClient(name: String = "", serverPort: Int): Client { - val client = Client( + private suspend fun initClient(name: String = "", serverPort: Int): McpClient { + val client = McpClient( Implementation(name = name, version = "1.0.0"), ) @@ -135,7 +135,7 @@ class WebSocketIntegrationTest { } private fun initServer(): EmbeddedServer { - val server = Server( + val server = McpServer( Implementation(name = "websocket-server", version = "1.0.0"), ServerOptions( capabilities = ServerCapabilities(prompts = ServerCapabilities.Prompts(listChanged = true)), @@ -177,7 +177,7 @@ class WebSocketIntegrationTest { /** * Retrieves a prompt result using the provided client and client name. */ - private suspend fun getPrompt(client: Client, clientName: String): String { + private suspend fun getPrompt(client: McpClient, clientName: String): String { val response = client.getPrompt( GetPromptRequest( "prompt", diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/AbstractKotlinClientTsServerTest.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/AbstractKotlinClientTsServerTest.kt index 51179982..a609d99b 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/AbstractKotlinClientTsServerTest.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/AbstractKotlinClientTsServerTest.kt @@ -2,7 +2,7 @@ package io.modelcontextprotocol.kotlin.sdk.integration.typescript import io.modelcontextprotocol.kotlin.sdk.CallToolResult import io.modelcontextprotocol.kotlin.sdk.TextContent -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Test @@ -13,7 +13,7 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue abstract class AbstractKotlinClientTsServerTest : TsTestBase() { - protected abstract suspend fun useClient(block: suspend (Client) -> T): T + protected abstract suspend fun useClient(block: suspend (McpClient) -> T): T @Test @Timeout(30, unit = TimeUnit.SECONDS) diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/TsTestBase.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/TsTestBase.kt index 801f5820..337713a1 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/TsTestBase.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/TsTestBase.kt @@ -4,12 +4,12 @@ import io.ktor.client.HttpClient import io.ktor.client.engine.cio.CIO import io.ktor.client.plugins.sse.SSE import io.modelcontextprotocol.kotlin.sdk.Implementation -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.client.StdioClientTransport import io.modelcontextprotocol.kotlin.sdk.client.mcpStreamableHttp import io.modelcontextprotocol.kotlin.sdk.integration.typescript.sse.KotlinServerForTsClient import io.modelcontextprotocol.kotlin.sdk.integration.utils.Retry -import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.McpServer import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport import kotlinx.coroutines.withTimeout import kotlinx.io.Sink @@ -283,10 +283,10 @@ abstract class TsTestBase { } // ===== SSE client helpers ===== - protected suspend fun newClient(serverUrl: String): Client = + protected suspend fun newClient(serverUrl: String): McpClient = HttpClient(CIO) { install(SSE) }.mcpStreamableHttp(serverUrl) - protected suspend fun withClient(serverUrl: String, block: suspend (Client) -> T): T { + protected suspend fun withClient(serverUrl: String, block: suspend (McpClient) -> T): T { val client = newClient(serverUrl) return try { withTimeout(20.seconds) { block(client) } @@ -338,16 +338,16 @@ abstract class TsTestBase { return process } - protected suspend fun newClientStdio(process: Process): Client { + protected suspend fun newClientStdio(process: Process): McpClient { val input: Source = process.inputStream.asSource().buffered() val output: Sink = process.outputStream.asSink().buffered() val transport = StdioClientTransport(input = input, output = output) - val client = Client(Implementation("test", "1.0")) + val client = McpClient(Implementation("test", "1.0")) client.connect(transport) return client } - protected suspend fun withClientStdio(block: suspend (Client, Process) -> T): T { + protected suspend fun withClientStdio(block: suspend (McpClient, Process) -> T): T { val proc = startTypeScriptServerStdio() val client = newClientStdio(proc) return try { @@ -403,7 +403,7 @@ abstract class TsTestBase { } // Create Kotlin server and attach stdio transport to the process streams - val server: Server = KotlinServerForTsClient().createMcpServer() + val server: McpServer = KotlinServerForTsClient().createMcpServer() val transport = StdioServerTransport( inputStream = process.inputStream.asSource().buffered(), outputStream = process.outputStream.asSink().buffered(), diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerEdgeCasesTestSse.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerEdgeCasesTestSse.kt index de275666..e42c535b 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerEdgeCasesTestSse.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerEdgeCasesTestSse.kt @@ -2,7 +2,7 @@ package io.modelcontextprotocol.kotlin.sdk.integration.typescript.sse import io.modelcontextprotocol.kotlin.sdk.CallToolResult import io.modelcontextprotocol.kotlin.sdk.TextContent -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.integration.typescript.TransportKind import io.modelcontextprotocol.kotlin.sdk.integration.typescript.TsTestBase import kotlinx.coroutines.Dispatchers @@ -31,7 +31,7 @@ class KotlinClientTsServerEdgeCasesTestSse : TsTestBase() { private val host = "localhost" private lateinit var serverUrl: String - private lateinit var client: Client + private lateinit var client: McpClient private lateinit var tsServerProcess: Process @BeforeEach diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerTestSse.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerTestSse.kt index 95a80f0b..957586a6 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerTestSse.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinClientTsServerTestSse.kt @@ -1,6 +1,6 @@ package io.modelcontextprotocol.kotlin.sdk.integration.typescript.sse -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.integration.typescript.AbstractKotlinClientTsServerTest import io.modelcontextprotocol.kotlin.sdk.integration.typescript.TransportKind import kotlinx.coroutines.withTimeout @@ -37,7 +37,7 @@ class KotlinClientTsServerTestSse : AbstractKotlinClientTsServerTest() { } } - override suspend fun useClient(block: suspend (Client) -> T): T = withClient(serverUrl) { client -> + override suspend fun useClient(block: suspend (McpClient) -> T): T = withClient(serverUrl) { client -> try { withTimeout(20.seconds) { block(client) } } finally { diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinServerForTsClientSse.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinServerForTsClientSse.kt index 5cb0f61b..939f254d 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinServerForTsClientSse.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/sse/KotlinServerForTsClientSse.kt @@ -35,7 +35,7 @@ import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities import io.modelcontextprotocol.kotlin.sdk.TextContent import io.modelcontextprotocol.kotlin.sdk.TextResourceContents import io.modelcontextprotocol.kotlin.sdk.Tool -import io.modelcontextprotocol.kotlin.sdk.server.Server +import io.modelcontextprotocol.kotlin.sdk.server.McpServer import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions import io.modelcontextprotocol.kotlin.sdk.shared.AbstractTransport import io.modelcontextprotocol.kotlin.sdk.shared.McpJson @@ -53,7 +53,6 @@ import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.contentOrNull import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.jsonPrimitive -import org.awaitility.Awaitility.await import java.util.UUID import java.util.concurrent.ConcurrentHashMap @@ -194,8 +193,8 @@ class KotlinServerForTsClient { server = null } - fun createMcpServer(): Server { - val server = Server( + fun createMcpServer(): McpServer { + val server = McpServer( Implementation( name = "kotlin-http-server", version = "1.0.0", diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerEdgeCasesTestStdio.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerEdgeCasesTestStdio.kt index b6e385f9..ad1aea2c 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerEdgeCasesTestStdio.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerEdgeCasesTestStdio.kt @@ -2,7 +2,7 @@ package io.modelcontextprotocol.kotlin.sdk.integration.typescript.stdio import io.modelcontextprotocol.kotlin.sdk.CallToolResult import io.modelcontextprotocol.kotlin.sdk.TextContent -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.integration.typescript.TransportKind import io.modelcontextprotocol.kotlin.sdk.integration.typescript.TsTestBase import kotlinx.coroutines.Dispatchers @@ -26,7 +26,7 @@ class KotlinClientTsServerEdgeCasesTestStdio : TsTestBase() { @Test @Timeout(30, unit = TimeUnit.SECONDS) fun testNonExistentToolOverStdio(): Unit = runBlocking(Dispatchers.IO) { - withClientStdio { client: Client, _ -> + withClientStdio { client: McpClient, _ -> val nonExistentToolName = "non-existent-tool" val arguments = mapOf("name" to "TestUser") @@ -50,7 +50,7 @@ class KotlinClientTsServerEdgeCasesTestStdio : TsTestBase() { @Test @Timeout(30, unit = TimeUnit.SECONDS) fun testSpecialCharactersInArgumentsOverStdio(): Unit = runBlocking(Dispatchers.IO) { - withClientStdio { client: Client, _ -> + withClientStdio { client: McpClient, _ -> val specialChars = "!@#$%^&*()_+{}[]|\\:;\"'<>.,?/" val arguments = mapOf("name" to specialChars) @@ -72,7 +72,7 @@ class KotlinClientTsServerEdgeCasesTestStdio : TsTestBase() { @Test @Timeout(30, unit = TimeUnit.SECONDS) fun testLargePayloadOverStdio(): Unit = runBlocking(Dispatchers.IO) { - withClientStdio { client: Client, _ -> + withClientStdio { client: McpClient, _ -> val largeName = "A".repeat(10 * 1024) val arguments = mapOf("name" to largeName) @@ -94,7 +94,7 @@ class KotlinClientTsServerEdgeCasesTestStdio : TsTestBase() { @Test @Timeout(60, unit = TimeUnit.SECONDS) fun testConcurrentRequestsOverStdio(): Unit = runBlocking(Dispatchers.IO) { - withClientStdio { client: Client, _ -> + withClientStdio { client: McpClient, _ -> val concurrentCount = 5 val responses = coroutineScope { val results = (1..concurrentCount).map { i -> @@ -130,7 +130,7 @@ class KotlinClientTsServerEdgeCasesTestStdio : TsTestBase() { @Test @Timeout(30, unit = TimeUnit.SECONDS) fun testInvalidArgumentsOverStdio(): Unit = runBlocking(Dispatchers.IO) { - withClientStdio { client: Client, _ -> + withClientStdio { client: McpClient, _ -> val invalidArguments = mapOf( "name" to JsonObject(mapOf("nested" to JsonPrimitive("value"))), ) @@ -155,7 +155,7 @@ class KotlinClientTsServerEdgeCasesTestStdio : TsTestBase() { @Test @Timeout(30, unit = TimeUnit.SECONDS) fun testMultipleToolCallsOverStdio(): Unit = runBlocking(Dispatchers.IO) { - withClientStdio { client: Client, _ -> + withClientStdio { client: McpClient, _ -> repeat(10) { i -> val name = "SequentialClient$i" val arguments = mapOf("name" to name) diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerTestStdio.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerTestStdio.kt index 82737249..7ff28aad 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerTestStdio.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/stdio/KotlinClientTsServerTestStdio.kt @@ -1,6 +1,6 @@ package io.modelcontextprotocol.kotlin.sdk.integration.typescript.stdio -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.integration.typescript.AbstractKotlinClientTsServerTest import io.modelcontextprotocol.kotlin.sdk.integration.typescript.TransportKind @@ -8,7 +8,7 @@ class KotlinClientTsServerTestStdio : AbstractKotlinClientTsServerTest() { override val transportKind = TransportKind.STDIO - override suspend fun useClient(block: suspend (Client) -> T): T = withClientStdio { client, proc -> + override suspend fun useClient(block: suspend (McpClient) -> T): T = withClientStdio { client, proc -> try { block(client) } finally { diff --git a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerTest.kt b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerTest.kt index 088444d6..e4fddd84 100644 --- a/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerTest.kt +++ b/kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerTest.kt @@ -13,7 +13,7 @@ import io.modelcontextprotocol.kotlin.sdk.TextContent import io.modelcontextprotocol.kotlin.sdk.TextResourceContents import io.modelcontextprotocol.kotlin.sdk.Tool import io.modelcontextprotocol.kotlin.sdk.ToolListChangedNotification -import io.modelcontextprotocol.kotlin.sdk.client.Client +import io.modelcontextprotocol.kotlin.sdk.client.McpClient import io.modelcontextprotocol.kotlin.sdk.shared.InMemoryTransport import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.launch @@ -35,7 +35,7 @@ class ServerTest { tools = ServerCapabilities.Tools(null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -47,7 +47,7 @@ class ServerTest { // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -70,14 +70,14 @@ class ServerTest { tools = ServerCapabilities.Tools(null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -106,7 +106,7 @@ class ServerTest { val serverOptions = ServerOptions( capabilities = ServerCapabilities(), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -126,7 +126,7 @@ class ServerTest { tools = ServerCapabilities.Tools(null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -141,7 +141,7 @@ class ServerTest { // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -164,7 +164,7 @@ class ServerTest { prompts = ServerCapabilities.Prompts(listChanged = false), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -180,7 +180,7 @@ class ServerTest { // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -203,7 +203,7 @@ class ServerTest { prompts = ServerCapabilities.Prompts(listChanged = false), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -226,7 +226,7 @@ class ServerTest { // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -249,7 +249,7 @@ class ServerTest { resources = ServerCapabilities.Resources(null, null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -275,7 +275,7 @@ class ServerTest { // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -298,7 +298,7 @@ class ServerTest { resources = ServerCapabilities.Resources(null, null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -341,7 +341,7 @@ class ServerTest { // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -364,14 +364,14 @@ class ServerTest { prompts = ServerCapabilities.Prompts(listChanged = false), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -400,7 +400,7 @@ class ServerTest { val serverOptions = ServerOptions( capabilities = ServerCapabilities(), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -420,14 +420,14 @@ class ServerTest { resources = ServerCapabilities.Resources(null, null), ), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) // Setup client val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client( + val client = McpClient( clientInfo = Implementation(name = "test client", version = "1.0"), ) @@ -461,7 +461,7 @@ class ServerTest { val serverOptions = ServerOptions( capabilities = ServerCapabilities(), ) - val server = Server( + val server = McpServer( Implementation(name = "test server", version = "1.0"), serverOptions, ) @@ -479,12 +479,12 @@ class ServerTest { val serverOptions = ServerOptions(capabilities = ServerCapabilities()) val instructions = "This is a test server. Use it for testing purposes only." - val server = Server(serverInfo, serverOptions, { instructions }) + val server = McpServer(serverInfo, serverOptions, { instructions }) // The instructions should be stored internally and used in handleInitialize // We can't directly access the private field, but we can test it through initialization val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client(clientInfo = Implementation(name = "test client", version = "1.0")) + val client = McpClient(clientInfo = Implementation(name = "test client", version = "1.0")) server.connect(serverTransport) client.connect(clientTransport) @@ -498,12 +498,12 @@ class ServerTest { val serverOptions = ServerOptions(capabilities = ServerCapabilities()) val instructions = "This is a test server. Use it for testing purposes only." - val server = Server(serverInfo, serverOptions, instructions) + val server = McpServer(serverInfo, serverOptions, instructions) // The instructions should be stored internally and used in handleInitialize // We can't directly access the private field, but we can test it through initialization val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client(clientInfo = Implementation(name = "test client", version = "1.0")) + val client = McpClient(clientInfo = Implementation(name = "test client", version = "1.0")) server.connect(serverTransport) client.connect(clientTransport) @@ -517,10 +517,10 @@ class ServerTest { val serverOptions = ServerOptions(capabilities = ServerCapabilities()) // Test that server works when instructions parameter is omitted (defaults to null) - val server = Server(serverInfo, serverOptions) + val server = McpServer(serverInfo, serverOptions) val (clientTransport, serverTransport) = InMemoryTransport.createLinkedPair() - val client = Client(clientInfo = Implementation(name = "test client", version = "1.0")) + val client = McpClient(clientInfo = Implementation(name = "test client", version = "1.0")) server.connect(serverTransport) client.connect(clientTransport)