Upgrade SDK to 0.8.0 in Weather STDIO server sample (#428)

Upgrade SDK version to 0.8.0 in Weather STDIO server sample

## Motivation and Context

Keep samples up to date

## How Has This Been Tested?
Locally + CI

## Breaking Changes
<!-- Will users need to update their code or configurations? -->

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [x] Refactoring

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [ ] I have added appropriate error handling
- [ ] I have added or updated documentation as needed

## Additional context
<!-- Add any other context, implementation notes, or design decisions
-->
This commit is contained in:
Konstantin Pavlov 2025-11-27 18:35:47 +02:00 • committed by GitHub
commit 29d89abf02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 14 deletions

View file

@ -8,14 +8,14 @@ import io.ktor.http.contentType
import io.ktor.http.headers
import io.ktor.serialization.kotlinx.json.json
import io.ktor.utils.io.streams.asInput
import io.modelcontextprotocol.kotlin.sdk.CallToolResult
import io.modelcontextprotocol.kotlin.sdk.Implementation
import io.modelcontextprotocol.kotlin.sdk.ServerCapabilities
import io.modelcontextprotocol.kotlin.sdk.TextContent
import io.modelcontextprotocol.kotlin.sdk.Tool
import io.modelcontextprotocol.kotlin.sdk.server.Server
import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions
import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport
import io.modelcontextprotocol.kotlin.sdk.types.CallToolResult
import io.modelcontextprotocol.kotlin.sdk.types.Implementation
import io.modelcontextprotocol.kotlin.sdk.types.ServerCapabilities
import io.modelcontextprotocol.kotlin.sdk.types.TextContent
import io.modelcontextprotocol.kotlin.sdk.types.ToolSchema
import kotlinx.coroutines.Job
import kotlinx.coroutines.runBlocking
import kotlinx.io.asSink
@ -28,7 +28,8 @@ import kotlinx.serialization.json.put
import kotlinx.serialization.json.putJsonObject
/**
* Starts an MCP server that provides weather-related tools for fetching active weather alerts by state and weather forecasts by latitude/longitude.
* Starts an MCP server that provides weather-related tools for fetching active
* weather alerts by state and weather forecasts by latitude/longitude.
*/
fun runMcpServer() {
// Base URL for the Weather API
@ -72,7 +73,7 @@ fun runMcpServer() {
description = """
Get weather alerts for a US state. Input is Two-letter US state code (e.g. CA, NY)
""".trimIndent(),
inputSchema = Tool.Input(
inputSchema = ToolSchema(
properties = buildJsonObject {
putJsonObject("state") {
put("type", "string")
@ -97,7 +98,7 @@ fun runMcpServer() {
description = """
Get weather forecast for a specific latitude/longitude
""".trimIndent(),
inputSchema = Tool.Input(
inputSchema = ToolSchema(
properties = buildJsonObject {
putJsonObject("latitude") {
put("type", "number")

View file

@ -1,16 +1,20 @@
package io.modelcontextprotocol.sample.client
import io.modelcontextprotocol.kotlin.sdk.Implementation
import io.modelcontextprotocol.kotlin.sdk.TextContent
import io.modelcontextprotocol.kotlin.sdk.client.Client
import io.modelcontextprotocol.kotlin.sdk.client.StdioClientTransport
import io.modelcontextprotocol.kotlin.sdk.types.Implementation
import io.modelcontextprotocol.kotlin.sdk.types.TextContent
import kotlinx.coroutines.runBlocking
import kotlinx.io.asSink
import kotlinx.io.asSource
import kotlinx.io.buffered
fun main(): Unit = runBlocking {
val process = ProcessBuilder("java", "-jar", "./build/libs/weather-stdio-server-0.1.0-all.jar")
val process = ProcessBuilder(
"java",
"-jar",
"${System.getProperty("user.dir")}/build/libs/weather-stdio-server-0.1.0-all.jar",
).redirectErrorStream(true)
.start()
val transport = StdioClientTransport(
@ -34,15 +38,15 @@ fun main(): Unit = runBlocking {
"latitude" to 38.5816,
"longitude" to -121.4944,
),
)?.content?.map { if (it is TextContent) it.text else it.toString() }
).content.map { if (it is TextContent) it.text else it.toString() }
println("Weather Forcast: ${weatherForecastResult?.joinToString(separator = "\n", prefix = "\n", postfix = "\n")}")
println("Weather Forecast: ${weatherForecastResult.joinToString(separator = "\n", prefix = "\n", postfix = "\n")}")
val alertResult =
client.callTool(
name = "get_alert",
arguments = mapOf("state" to "TX"),
)?.content?.map { if (it is TextContent) it.text else it.toString() }
).content.map { if (it is TextContent) it.text else it.toString() }
println("Alert Response = $alertResult")