@@ -11,15 +11,15 @@ import kotlinx.io.asSource
1111import kotlinx.io.buffered
1212import kotlinx.serialization.json.JsonObject
1313import kotlinx.serialization.json.JsonPrimitive
14-
14+ import kotlinx.serialization.json.buildJsonObject
1515
1616fun main (): Unit = runBlocking {
17- val process = ProcessBuilder (" java" , " -jar" , " build/libs/weather-stdio-server-0.1.0-all.jar" )
17+ val process = ProcessBuilder (" java" , " -jar" , " ./ build/libs/weather-stdio-server-0.1.0-all.jar" )
1818 .start()
1919
2020 val transport = StdioClientTransport (
2121 input = process.inputStream.asSource().buffered(),
22- output = process.outputStream.asSink().buffered()
22+ output = process.outputStream.asSink().buffered(),
2323 )
2424
2525 // Initialize the MCP client with client information
@@ -29,15 +29,17 @@ fun main(): Unit = runBlocking {
2929
3030 client.connect(transport)
3131
32-
33- val toolsList = client.listTools()?.tools?.map { it.name }
32+ val toolsList = client.listTools().tools.map { it.name }
3433 println (" Available Tools = $toolsList " )
3534
3635 val weatherForecastResult = client.callTool(
3736 CallToolRequest (
3837 name = " get_forecast" ,
39- arguments = JsonObject (mapOf (" latitude" to JsonPrimitive (38.5816 ), " longitude" to JsonPrimitive (- 121.4944 )))
40- )
38+ arguments = buildJsonObject {
39+ put(" latitude" , JsonPrimitive (38.5816 ))
40+ put(" longitude" , JsonPrimitive (- 121.4944 ))
41+ },
42+ ),
4143 )?.content?.map { if (it is TextContent ) it.text else it.toString() }
4244
4345 println (" Weather Forcast: ${weatherForecastResult?.joinToString(separator = " \n " , prefix = " \n " , postfix = " \n " )} " )
@@ -46,11 +48,11 @@ fun main(): Unit = runBlocking {
4648 client.callTool(
4749 CallToolRequest (
4850 name = " get_alerts" ,
49- arguments = JsonObject (mapOf (" state" to JsonPrimitive (" TX" )))
50- )
51+ arguments = JsonObject (mapOf (" state" to JsonPrimitive (" TX" ))),
52+ ),
5153 )?.content?.map { if (it is TextContent ) it.text else it.toString() }
5254
5355 println (" Alert Response = $alertResult " )
5456
5557 client.close()
56- }
58+ }
0 commit comments