Skip to content

Commit a4d765c

Browse files
authored
Refactor for simplify JSON object construction for input schemas using buildJsonObject (#65)
1 parent 1c5e549 commit a4d765c

File tree

1 file changed

+14
-16
lines changed
  • samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server

1 file changed

+14
-16
lines changed

samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/McpWeatherServer.kt

+14-16
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,12 @@ fun `run mcp server`() {
5858
Get weather alerts for a US state. Input is Two-letter US state code (e.g. CA, NY)
5959
""".trimIndent(),
6060
inputSchema = Tool.Input(
61-
properties = JsonObject(
62-
mapOf(
63-
"state" to JsonObject(
64-
mapOf(
65-
"type" to JsonPrimitive("string"),
66-
"description" to JsonPrimitive("Two-letter US state code (e.g. CA, NY)")
67-
)
68-
),
69-
)
70-
),
61+
properties = buildJsonObject {
62+
putJsonObject("state") {
63+
put("type", "string")
64+
put("description", "Two-letter US state code (e.g. CA, NY)")
65+
}
66+
},
7167
required = listOf("state")
7268
)
7369
) { request ->
@@ -90,12 +86,14 @@ fun `run mcp server`() {
9086
Get weather forecast for a specific latitude/longitude
9187
""".trimIndent(),
9288
inputSchema = Tool.Input(
93-
properties = JsonObject(
94-
mapOf(
95-
"latitude" to JsonObject(mapOf("type" to JsonPrimitive("number"))),
96-
"longitude" to JsonObject(mapOf("type" to JsonPrimitive("number"))),
97-
)
98-
),
89+
properties = buildJsonObject {
90+
putJsonObject("latitude") {
91+
put("type", "number")
92+
}
93+
putJsonObject("longitude") {
94+
put("type", "number")
95+
}
96+
},
9997
required = listOf("latitude", "longitude")
10098
)
10199
) { request ->

0 commit comments

Comments
 (0)