kotlin-sdk/samples/weather-stdio-server
Repository files (latest commit first)
Filename Latest commit message Latest commit date
dependabot[bot] f9d491e4fa
Bump gradle-wrapper from 9.3.0 to 9.3.1 (#523)
Bumps gradle-wrapper from 9.3.0 to 9.3.1.


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=gradle-wrapper&package-manager=gradle&previous-version=9.3.0&new-version=9.3.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Konstantin Pavlov <1517853+kpavlov@users.noreply.github.com>
2026-02-16 10:31:59 +02:00
..
gradle Bump gradle-wrapper from 9.3.0 to 9.3.1 (#523) 2026-02-16 10:31:59 +02:00
src Upgrade SDK to 0.8.0 in Weather STDIO server sample (#428) 2025-11-27 18:35:47 +02:00
build.gradle.kts Add Ktor BOM for dependency management across all modules, run Kotlin-MCP-Server Sample (#367) 2025-11-04 11:44:39 +02:00
gradle.properties #302 Update samples build workflow (#330) 2025-10-23 13:02:22 +03:00
gradlew #302 Update samples build workflow (#330) 2025-10-23 13:02:22 +03:00
gradlew.bat #302 Update samples build workflow (#330) 2025-10-23 13:02:22 +03:00
README.md #302 Update samples build workflow (#330) 2025-10-23 13:02:22 +03:00
settings.gradle.kts #302 Update samples build workflow (#330) 2025-10-23 13:02:22 +03:00

Kotlin MCP Weather STDIO Server

This project demonstrates how to build a Model Context Protocol (MCP) server in Kotlin that provides weather-related tools by consuming the National Weather Service (weather.gov) API. The server uses STDIO as the transport layer and leverages the Kotlin MCP SDK to expose weather forecast and alert tools.

For more information about the MCP SDK and protocol, please refer to the MCP documentation.

Prerequisites

  • Java 17 or later
  • Gradle (or the Gradle wrapper provided with the project)
  • Basic understanding of MCP concepts
  • Basic understanding of Kotlin and Kotlin ecosystems (sush as kotlinx-serialization, coroutines, ktor)

MCP Weather Server

The project provides:

  • A lightweight MCP server built with Kotlin.
  • STDIO transport layer implementation for server-client communication.
  • Two weather tools:
    • Weather Forecast Tool — returns details such as temperature, wind information, and a detailed forecast for a given latitude/longitude.
    • Weather Alerts Tool — returns active weather alerts for a given US state.

Building and running

Use the Gradle wrapper to build the application. In a terminal run:

./gradlew clean build

To run the server:

java -jar build/libs/weather-stdio-server-0.1.0-all.jar

Note

The server uses STDIO transport, so it is typically launched in an environment where the client connects via standard input/output.

Tool Implementation

The project registers two MCP tools using the Kotlin MCP SDK. Below is an overview of the core tool implementations:

1. Weather Forecast Tool

This tool fetches the weather forecast for a specific latitude and longitude using the weather.gov API.

Example tool registration in Kotlin:

server.addTool(
    name = "get_forecast",
    description = """
            Get weather forecast for a specific latitude/longitude
        """.trimIndent(),
    inputSchema = Tool.Input(
        properties = JsonObject(
            mapOf(
                "latitude" to JsonObject(mapOf("type" to JsonPrimitive("number"))),
                "longitude" to JsonObject(mapOf("type" to JsonPrimitive("number"))),
            )
        ),
        required = listOf("latitude", "longitude")
    )
) { request ->
    // Implementation tool
}

2. Weather Alerts Tool

This tool retrieves active weather alerts for a US state.

Example tool registration in Kotlin:

server.addTool(
    name = "get_alerts",
    description = """
        Get weather alerts for a US state. Input is Two-letter US state code (e.g. CA, NY)
    """.trimIndent(),
    inputSchema = Tool.Input(
        properties = JsonObject(
            mapOf(
                "state" to JsonObject(
                    mapOf(
                        "type" to JsonPrimitive("string"),
                        "description" to JsonPrimitive("Two-letter US state code (e.g. CA, NY)")
                    )
                ),
            )
        ),
        required = listOf("state")
    )
) { request ->
    // Implementation tool
}

Client Integration

Kotlin Client Example

Since the server uses STDIO for transport, the client typically connects via standard input/output streams. A sample client implementation can be found in the tests, demonstrating how to send tool requests and process responses.

Claude for Desktop

To integrate with Claude Desktop, add the following configuration to your Claude Desktop settings:

{
  "mcpServers": {
    "weather": {
      "command": "java",
      "args": [
        "-jar",
        "/absolute/path/to/<your-jar-name>.jar"
      ]
    }
  }
}

Note

Replace /absolute/path/to/<your-jar-name>.jar with the actual absolute path to your built jar file.

Additional Resources