Spring AI MCP Weather Server Sample with WebMVC Starter
About
# Spring AI MCP Weather Server Sample with WebMVC Starter This sample project demonstrates how to create an MCP server using the Spring AI MCP Server Boot Starter with WebMVC transport. It implements a weather service that exposes tools for retrieving weather information using the National Weather Service API. For…
Explore
- Integration with spring-ai-mcp-server-webmvc-spring-boot-starter
- Supports both SSE (Server-Sent Events) and STDIO transports
- Automatic tool registration using Spring AI’s @Tool annotation
- Two weather tools: forecast by location and alerts by US state
- Auto-configured SSE endpoints with WebMVC transport
- Optional change notifications for resources, tools, and prompts
Configure the server through application.properties:
```properties
The server supports two transport modes:
spring.ai.mcp.server.stdio=false
spring.ai.mcp.server.sse-message-endpoint=/mcp/message
latitude
double - Latitude coordinate
longitude
double - Longitude coordinate
state
String - Two-letter US state code (e.g., CA, NY)
- Name: getWeatherForecastByLocation
- Description: Get weather forecast for a specific latitude/longitude
- Parameters:
- latitude: double - Latitude coordinate
- longitude: double - Longitude coordinate
- Name: getAlerts
- Description: Get weather alerts for a US state
- Parameters:
- state: String - Two-letter US state code (e.g., CA, NY)
This sample project demonstrates how to create an MCP server using the Spring AI MCP Server Boot Starter with WebMVC transport. It implements a weather service that exposes tools for retrieving weather information using the National Weather Service API.
For more information, see the MCP Server Boot Starter reference documentation.
Overview
The sample showcases:
- Integration with spring-ai-mcp-server-webmvc-spring-boot-starter
- Support for both SSE (Server-Sent Events) and STDIO transports
- Automatic tool registration using Spring AI's @Tool annotation
- Two weather-related tools:
- Get weather forecast by location (latitude/longitude)
- Get weather alerts by US state
Dependencies
The project requires the Spring AI MCP Server WebMVC Boot Starter:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mcp-server-webmvc-spring-boot-starter</artifactId>
</dependency>
This starter provides:
- HTTP-based transport using Spring MVC (WebMvcSseServerTransport)
- Auto-configured SSE endpoints
- Optional STDIO transport
- Included spring-boot-starter-web and mcp-spring-webmvc dependencies
Building the Project
Build the project using Maven:
./mvnw clean install -DskipTests
Running the Server
The server supports two transport modes:
WebMVC SSE Mode (Default)
java -jar target/mcp-weather-starter-webmvc-server-0.0.1-SNAPSHOT.jar
STDIO Mode
To enable STDIO transport, set the appropriate properties:java -Dspring.ai.mcp.server.stdio=true -Dspring.main.web-application-type=none -jar target/mcp-weather-starter-webmvc-server-0.0.1-SNAPSHOT.jar
Configuration
Configure the server through application.properties:
```properties
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



