Skip to content

Commit d43c62c

Browse files
authored
Merge branch 'modelcontextprotocol:main' into add-meta-in-call-tool-method
2 parents 5a31507 + d962e28 commit d43c62c

File tree

27 files changed

+3807
-607
lines changed

27 files changed

+3807
-607
lines changed

build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ dokka {
3333
}
3434
}
3535

36+
ktlint {
37+
filter {
38+
exclude("**/generated*/**")
39+
}
40+
}
41+
3642
kover {
3743
reports {
3844
filters {
3945
includes.classes("io.modelcontextprotocol.kotlin.sdk.*")
46+
excludes.classes("io.modelcontextprotocol.kotlin.sdk.models.*") // temporary
47+
excludes.classes("io.modelcontextprotocol.kotlin.sdk.models.infrastructure.*") // generated
4048
}
4149
total {
4250
log {

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ktor-server-core = { group = "io.ktor", name = "ktor-server-core", version.ref =
4848

4949
# Testing
5050
awaitility = { group = "org.awaitility", name = "awaitility-kotlin", version.ref = "awaitility" }
51+
kotest-assertions-core = { group = "io.kotest", name = "kotest-assertions-core", version.ref = "kotest" }
5152
kotest-assertions-json = { group = "io.kotest", name = "kotest-assertions-json", version.ref = "kotest" }
5253
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines" }
5354
ktor-client-mock = { group = "io.ktor", name = "ktor-client-mock", version.ref = "ktor" }

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ public open class Client(private val clientInfo: Implementation, options: Client
159159

160160
notification(InitializedNotification())
161161
} catch (error: Throwable) {
162+
logger.error(error) { "Failed to initialize client: ${error.message}" }
162163
close()
164+
163165
if (error !is CancellationException) {
164-
throw IllegalStateException("Error connecting to transport: ${error.message}")
166+
throw IllegalStateException("Error connecting to transport: ${error.message}", error)
165167
}
166168

167169
throw error

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.modelcontextprotocol.kotlin.sdk.client
22

3+
import io.github.oshai.kotlinlogging.KotlinLogging
34
import io.ktor.client.HttpClient
45
import io.ktor.client.plugins.sse.ClientSSESession
56
import io.ktor.client.plugins.sse.sseSession
@@ -46,6 +47,8 @@ public class SseClientTransport(
4647
private val reconnectionTime: Duration? = null,
4748
private val requestBuilder: HttpRequestBuilder.() -> Unit = {},
4849
) : AbstractTransport() {
50+
private val logger = KotlinLogging.logger {}
51+
4952
private val initialized: AtomicBoolean = AtomicBoolean(false)
5053
private val endpoint = CompletableDeferred<String>()
5154

@@ -111,6 +114,8 @@ public class SseClientTransport(
111114
val text = response.bodyAsText()
112115
error("Error POSTing to endpoint (HTTP ${response.status}): $text")
113116
}
117+
118+
logger.debug { "Client successfully sent message via SSE $endpoint" }
114119
} catch (e: Throwable) {
115120
_onError(e)
116121
throw e
@@ -158,6 +163,7 @@ public class SseClientTransport(
158163
val path = if (eventData.startsWith("/")) eventData.substring(1) else eventData
159164
val endpointUrl = Url("$baseUrl/$path")
160165
endpoint.complete(endpointUrl.toString())
166+
logger.debug { "Client connected to endpoint: $endpointUrl" }
161167
} catch (e: Throwable) {
162168
_onError(e)
163169
endpoint.completeExceptionally(e)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.modelcontextprotocol.kotlin.sdk.client
22

3+
import io.github.oshai.kotlinlogging.KotlinLogging
34
import io.ktor.client.HttpClient
45
import io.ktor.client.plugins.websocket.webSocketSession
56
import io.ktor.client.request.HttpRequestBuilder
@@ -10,6 +11,8 @@ import io.modelcontextprotocol.kotlin.sdk.shared.MCP_SUBPROTOCOL
1011
import io.modelcontextprotocol.kotlin.sdk.shared.WebSocketMcpTransport
1112
import kotlin.properties.Delegates
1213

14+
private val logger = KotlinLogging.logger {}
15+
1316
/**
1417
* Client transport for WebSocket: this will connect to a server over the WebSocket protocol.
1518
*/
@@ -21,6 +24,8 @@ public class WebSocketClientTransport(
2124
override var session: WebSocketSession by Delegates.notNull()
2225

2326
override suspend fun initializeSession() {
27+
logger.debug { "Websocket session initialization started..." }
28+
2429
session = urlString?.let {
2530
client.webSocketSession(it) {
2631
requestBuilder()
@@ -32,5 +37,7 @@ public class WebSocketClientTransport(
3237

3338
header(HttpHeaders.SecWebSocketProtocol, MCP_SUBPROTOCOL)
3439
}
40+
41+
logger.debug { "Websocket session initialization finished" }
3542
}
3643
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package io.modelcontextprotocol.kotlin.sdk.client
22

3+
import io.github.oshai.kotlinlogging.KotlinLogging
34
import io.ktor.client.HttpClient
45
import io.ktor.client.request.HttpRequestBuilder
56
import io.modelcontextprotocol.kotlin.sdk.Implementation
67
import io.modelcontextprotocol.kotlin.sdk.LIB_VERSION
78
import io.modelcontextprotocol.kotlin.sdk.shared.IMPLEMENTATION_NAME
89

10+
private val logger = KotlinLogging.logger {}
11+
912
/**
1013
* Returns a new WebSocket transport for the Model Context Protocol using the provided HttpClient.
1114
*
@@ -36,6 +39,8 @@ public suspend fun HttpClient.mcpWebSocket(
3639
version = LIB_VERSION,
3740
),
3841
)
42+
logger.debug { "Client started to connect to server" }
3943
client.connect(transport)
44+
logger.debug { "Client finished to connect to server" }
4045
return client
4146
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
**/auth/**
10+
**/infrastructure/**
11+
!**/Base64ByteArray.kt
12+
!**/Bytes.kt
13+
14+
15+
## Exclude Models which are causing problems
16+
**/JSONRPCResponse.kt
17+
**/Result.kt
18+
**/ListToolsResult.kt
19+
**/InitializeRequest.kt
20+
**/InitializeResult.kt
21+
**/ServerCapabilities.kt
22+
**/InitializeRequestParams.kt
23+
**/CreateMessageRequest.kt
24+
**/CreateMessageRequestParams.kt
25+
**/ClientCapabilities.kt
26+
**/Tool.kt
27+
**/ToolInputSchema.kt
28+
**/ToolOutputSchema.kt
29+

0 commit comments

Comments
 (0)