Java / Maven

MCP Weather Server with HTTP transport

Build an MCP weather server with HTTP transport.

Sergio del Amo
On this guide
In this section

Getting Started

In this guide, we will create a Micronaut application written in Java.

What you will need

To complete this guide, you will need the following:

Solution

We recommend that you follow the instructions in the next sections and create the application step by step. However, you can go right to the completed example.

Create an application using the Micronaut Command Line Interface or with Micronaut Launch.

What will you build?

In this guide, we will create an MCP Server with Micronaut like the one described in the Build an MCP server tutorial on the Model Context Protocol website.

Dependency

Add the Micronaut MCP Server Java SDK dependency to your build file:

pom.xml
<dependency>
    <groupId>io.micronaut.mcp</groupId>
    <artifactId>micronaut-mcp-server-java-sdk</artifactId>
    <scope>compile</scope>
</dependency>

To use Micronaut JSON Schema generation capabilities, add the following dependencies:

pom.xml
<!-- Add the following to your annotationProcessorPaths element -->
<path>
    <groupId>io.micronaut.jsonschema</groupId>
    <artifactId>micronaut-json-schema-processor</artifactId>
</path>
<dependency>
    <groupId>io.micronaut.jsonschema</groupId>
    <artifactId>micronaut-json-schema-annotations</artifactId>
    <scope>compile</scope>
</dependency>

Configuration

src/main/resources/application.properties

JSON Schema Generation

An MCP Tool can define its input schema using JSON Schema.

Thanks to Micronaut JSON Schema, we can generate the JSON Schema at compile-time given a Java file.

Create two Java records to model the tools' inputs.

GetAlertInput will be the input schema of the getAlerts tool.

src/main/java/example/micronaut/GetAlertInput.java

Point will be the input schema of the getWeatherForecastByLocation tool.

src/main/java/example/micronaut/Point.java

MCP Tool

The MCP Server exposes two tools: getWeatherForecastByLocation and getAlerts.

src/main/java/example/micronaut/Tools.java

WeatherClient is a Micronaut bean that uses the Micronaut HTTP Client to consume the https://api.weather.gov API. Please download the complete project to check the code.

MCP Inspector

To test the MCP Server, run the MCP inspector.

Select Streamable HTTP as Transport type.

Enter http://localhost:8080/mcp as the URL.

Click connect. You will be able to list tools and invoke the getWeatherForecastByLocation tool.

Note
The https://api.weather.gov API works only for US locations.

You will also be able to invoke the getAlerts tool.

mcp weather http

Next Steps

Explore more features with Micronaut Guides.

License

Note
All guides are released with an Apache License 2.0 for the code and a Creative Commons Attribution 4.0 license for the writing and media (images).