Skip to content

Commit 65089dc

Browse files
committed
ToolSerializationTest update
1 parent 4ed91a0 commit 65089dc

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

src/commonTest/kotlin/ToolSerializationTest.kt

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,52 @@ import kotlinx.serialization.encodeToString
66
import kotlinx.serialization.json.JsonPrimitive
77
import kotlinx.serialization.json.buildJsonObject
88
import kotlin.test.Test
9+
import kotlin.test.assertEquals
910

1011
class ToolSerializationTest {
1112

12-
@Test
13-
fun `should serialize GetWeather tool`() {
14-
val tool = Tool(
15-
name = "get_weather",
16-
description = "Get the current weather in a given location",
17-
inputSchema = Tool.Input(
18-
properties = buildJsonObject {
19-
put("location", buildJsonObject {
20-
put("type", JsonPrimitive("string"))
21-
put("description", JsonPrimitive("The city and state, e.g. San Francisco, CA"))
22-
})
23-
},
24-
required = listOf("location")
25-
)
13+
// see https://docs.anthropic.com/en/docs/build-with-claude/tool-use
14+
/* language=json */
15+
private val getWeatherToolJson = """
16+
{
17+
"name": "get_weather",
18+
"description": "Get the current weather in a given location",
19+
"inputSchema": {
20+
"type": "object",
21+
"properties": {
22+
"location": {
23+
"type": "string",
24+
"description": "The city and state, e.g. San Francisco, CA"
25+
}
26+
},
27+
"required": ["location"]
28+
}
29+
}
30+
""".trimIndent()
31+
32+
val getWeatherTool = Tool(
33+
name = "get_weather",
34+
description = "Get the current weather in a given location",
35+
inputSchema = Tool.Input(
36+
properties = buildJsonObject {
37+
put("location", buildJsonObject {
38+
put("type", JsonPrimitive("string"))
39+
put("description", JsonPrimitive("The city and state, e.g. San Francisco, CA"))
40+
})
41+
},
42+
required = listOf("location")
2643
)
44+
)
2745

28-
// see https://docs.anthropic.com/en/docs/build-with-claude/tool-use
29-
McpJson.encodeToString(tool) shouldEqualJson /* language=json */ """
30-
{
31-
"name": "get_weather",
32-
"description": "Get the current weather in a given location",
33-
"inputSchema": {
34-
"type": "object",
35-
"properties": {
36-
"location": {
37-
"type": "string",
38-
"description": "The city and state, e.g. San Francisco, CA"
39-
}
40-
},
41-
"required": ["location"]
42-
}
43-
}
44-
"""
46+
@Test
47+
fun `should serialize get_weather tool`() {
48+
McpJson.encodeToString(getWeatherTool) shouldEqualJson getWeatherToolJson
49+
}
50+
51+
@Test
52+
fun `should deserialize get_weather tool`() {
53+
val tool = McpJson.decodeFromString<Tool>(getWeatherToolJson)
54+
assertEquals(expected = getWeatherTool, actual = tool)
4555
}
4656

47-
}
57+
}

0 commit comments

Comments
 (0)