Refactor for simplify JSON object construction for input schemas using buildJsonObject (#65)

This commit is contained in:
Pavel Gorgulov 2025-04-02 11:23:26 +02:00 • committed by GitHub
commit a4d765cf94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -58,16 +58,12 @@ fun `run mcp server`() {
Get weather alerts for a US state. Input is Two-letter US state code (e.g. CA, NY) Get weather alerts for a US state. Input is Two-letter US state code (e.g. CA, NY)
""".trimIndent(), """.trimIndent(),
inputSchema = Tool.Input( inputSchema = Tool.Input(
properties = JsonObject( properties = buildJsonObject {
mapOf( putJsonObject("state") {
"state" to JsonObject( put("type", "string")
mapOf( put("description", "Two-letter US state code (e.g. CA, NY)")
"type" to JsonPrimitive("string"), }
"description" to JsonPrimitive("Two-letter US state code (e.g. CA, NY)") },
)
),
)
),
required = listOf("state") required = listOf("state")
) )
) { request -> ) { request ->
@ -90,12 +86,14 @@ fun `run mcp server`() {
Get weather forecast for a specific latitude/longitude Get weather forecast for a specific latitude/longitude
""".trimIndent(), """.trimIndent(),
inputSchema = Tool.Input( inputSchema = Tool.Input(
properties = JsonObject( properties = buildJsonObject {
mapOf( putJsonObject("latitude") {
"latitude" to JsonObject(mapOf("type" to JsonPrimitive("number"))), put("type", "number")
"longitude" to JsonObject(mapOf("type" to JsonPrimitive("number"))), }
) putJsonObject("longitude") {
), put("type", "number")
}
},
required = listOf("latitude", "longitude") required = listOf("latitude", "longitude")
) )
) { request -> ) { request ->