Skip to content

Commit 98d8de7

Browse files
committed
add test
1 parent b23faa6 commit 98d8de7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,13 +1046,16 @@ public data class Tool(
10461046
/**
10471047
* A JSON object defining the expected parameters for the tool.
10481048
*/
1049+
@SerialName("input_schema")
10491050
val inputSchema: Input,
10501051
) {
10511052
@Serializable
10521053
public data class Input(
10531054
val properties: JsonObject = EmptyJsonObject,
10541055
val required: List<String>? = null,
10551056
) {
1057+
@OptIn(ExperimentalSerializationApi::class)
1058+
@EncodeDefault
10561059
val type: String = "object"
10571060
}
10581061
}

src/commonTest/kotlin/ToolSerializationTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.modelcontextprotocol.kotlin.sdk
33
import io.kotest.assertions.json.shouldEqualJson
44
import io.modelcontextprotocol.kotlin.sdk.shared.McpJson
55
import kotlinx.serialization.encodeToString
6+
import kotlinx.serialization.json.Json
67
import kotlinx.serialization.json.JsonPrimitive
78
import kotlinx.serialization.json.buildJsonObject
89
import kotlin.test.Test
@@ -54,4 +55,11 @@ class ToolSerializationTest {
5455
assertEquals(expected = getWeatherTool, actual = tool)
5556
}
5657

58+
@Test
59+
fun `should always serialize default value`() {
60+
val json = Json(from = McpJson) {
61+
encodeDefaults = false
62+
}
63+
json.encodeToString(getWeatherTool) shouldEqualJson getWeatherToolJson
64+
}
5765
}

0 commit comments

Comments
 (0)