Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Spring AI MCP Weather Server — WebFlux Starter

MCP server built with the Spring AI WebFlux starter. Exposes weather tools via Streamable HTTP (default) and STDIO transports.

Reference docs: MCP Server Boot Starter

Dependency

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-mcp-server-webflux</artifactId>
</dependency>

Build

./mvnw clean install -DskipTests

Run

Streamable HTTP (default, port 8080)

java -jar target/mcp-weather-starter-webflux-server-0.0.1-SNAPSHOT.jar

STDIO

java -Dspring.ai.mcp.server.stdio=true \
     -Dspring.main.web-application-type=none \
     -Dspring.main.banner-mode=off \
     -Dlogging.pattern.console= \
     -jar target/mcp-weather-starter-webflux-server-0.0.1-SNAPSHOT.jar

Configuration

spring.ai.mcp.server.name=my-weather-server
spring.ai.mcp.server.version=0.0.1
spring.ai.mcp.server.protocol=STREAMABLE

# Required when using STDIO transport
# spring.main.banner-mode=off
# logging.pattern.console=

Tools

Tool Description
getWeatherForecastByLocation Forecast for a latitude/longitude (weather.gov)
getAlerts Active alerts for a two-letter US state code (e.g. NY)
toUpperCase Converts input text to upper case

Weather tools are registered via @McpTool on WeatherService. toUpperCase is registered programmatically in McpServerApplication.

Sample Clients

Three standalone clients are provided under src/main/java/.../client/:

Client Transport
StreamableHttpClient.java Streamable HTTP (WebClientStreamableHttpTransport)
ClientSse.java SSE (WebFluxSseClientTransport)
ClientStdio.java STDIO (StdioClientTransport) — starts the server automatically

Streamable HTTP

var transport = WebClientStreamableHttpTransport.builder(
        WebClient.builder().baseUrl("http://localhost:8080"))
    .build();
var client = McpClient.sync(transport).build();
client.initialize();

SSE

var transport = new WebFluxSseClientTransport(
        WebClient.builder().baseUrl("http://localhost:8080"),
        McpJsonDefaults.getMapper());
var client = McpClient.sync(transport).build();
client.initialize();

STDIO

var params = ServerParameters.builder("java")
    .args("-Dspring.ai.mcp.server.stdio=true",
          "-Dspring.main.web-application-type=none",
          "-Dspring.main.banner-mode=off",
          "-Dlogging.pattern.console=",
          "-jar", "target/mcp-weather-starter-webflux-server-0.0.1-SNAPSHOT.jar")
    .build();
var transport = new StdioClientTransport(params, McpJsonDefaults.getMapper());
var client = McpClient.sync(transport).build();
client.initialize();

Boot Starter Clients

For a higher-level client experience see the starter-default-client and starter-webflux-client projects. They auto-configure STDIO and/or SSE connections via mcp-servers-config.json.

STDIO via starter client

mcp-servers-config.json:

{
  "mcpServers": {
    "weather": {
      "command": "java",
      "args": [
        "-Dspring.ai.mcp.server.stdio=true",
        "-Dspring.main.web-application-type=none",
        "-Dlogging.pattern.console=",
        "-jar",
        "/absolute/path/to/mcp-weather-starter-webflux-server-0.0.1-SNAPSHOT.jar"
      ]
    }
  }
}
java -Dspring.ai.mcp.client.stdio.servers-configuration=file:mcp-servers-config.json \
     -Dai.user.input='What is the weather in NY?' \
     -Dlogging.pattern.console= \
     -jar mcp-starter-webflux-client-0.0.1-SNAPSHOT.jar

SSE via starter client

# Terminal 1 — start the server
java -jar mcp-weather-starter-webflux-server-0.0.1-SNAPSHOT.jar

# Terminal 2 — run the client
java -Dspring.ai.mcp.client.sse.connections.weather-server.url=http://localhost:8080 \
     -Dai.user.input='What is the weather in NY?' \
     -Dlogging.pattern.console= \
     -jar mcp-starter-webflux-client-0.0.1-SNAPSHOT.jar