Spring AI Weather Server

by minggh

Not rated
GitHub

About

An MCP server providing weather tools from the National Weather Service (weather.gov) API, built with Spring Boot.

Details

Author
minggh
Categories
Cloud Service, Other, API
Tags
#weather, #data-analysis

Setup

Install Spring AI Weather Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/minggh/starter-stdio-server

Follow the installation instructions in the repository README, then restart your MCP client.

The code source of this project is:spring-ai-examples | starter-stdio-server, and the OPEN SOURCE LICENSE follows the original project.

本项目代码来源:spring-ai-examples | starter-stdio-server, 开源许可证遵循原始项目

A Spring Boot starter project demonstrating how to build a Model Context Protocol (MCP) server that provides weather-related tools using the National Weather Service (weather.gov) API. This project showcases the Spring AI MCP Server Boot Starter capabilities with STDIO transport implementation.

For more information, see theMCP Server Boot Starterreference documentation.

- Java 17 or later
- Maven 3.6 or later
- Understanding of Spring Boot and Spring AI concepts
- (Optional) Claude Desktop for AI assistant integration

Thespring-ai-mcp-server-spring-boot-starterprovides:

- Automatic configuration of MCP server components
- Support for both synchronous and asynchronous operation modes
- STDIO transport layer implementation
- Flexible tool registration through Spring beans
- Change notification capabilities

src/ ├── main/ │ ├── java/ │ │ └── org/springframework/ai/mcp/sample/server/ │ │ ├── McpServerApplication.java # Main application class with tool registration │ │ └── WeatherService.java # Weather service implementation with MCP tools │ └── resources/ │ └── application.properties # Server and transport configuration └── test/ └── java/ └── org/springframework/ai/mcp/sample/client/ └── ClientStdio.java # Test client implementation

The server uses STDIO transport mode and is typically started automatically by the client. To build the server jar:

The project demonstrates how to implement and register MCP tools using Spring's dependency injection and auto-configuration:

@Service public class WeatherService { @Tool(description = "Get weather forecast for a specific latitude/longitude") public String getWeatherForecastByLocation( double latitude, // Latitude coordinate double longitude // Longitude coordinate ) { // Implementation } @Tool(description = "Get weather alerts for a US state") public String getAlerts( String state // Two-letter US state code (e.g., CA, NY) ) { // Implementation } } @SpringBootApplication public class McpServerApplication { @Bean public List<ToolCallback> weatherTools(WeatherService weatherService) { return ToolCallbacks.from(weatherService); } }

The auto-configuration automatically registers these tools with the MCP server. You can have multiple beans producing lists of ToolCallbacks, and the auto-configuration will merge them.

@Tool(description = "Get weather forecast for a specific latitude/longitude") public String getWeatherForecastByLocation( double latitude, // Latitude coordinate double longitude // Longitude coordinate ) { // Returns detailed forecast including: // - Temperature and unit // - Wind speed and direction // - Detailed forecast description } // Example usage: CallToolResult forecast = client.callTool( new CallToolRequest("getWeatherForecastByLocation", Map.of( "latitude", 47.6062, // Seattle coordinates "longitude", -122.3321 ) ) );
@Tool(description = "Get weather alerts for a US state") public String getAlerts( String state // Two-letter US state code (e.g., CA, NY) ) { // Returns active alerts including: // - Event type // - Affected area // - Severity // - Description // - Safety instructions } // Example usage: CallToolResult alerts = client.callTool( new CallToolRequest("getAlerts", Map.of("state", "NY") ) );
// Create server parameters ServerParameters stdioParams = ServerParameters.builder("java") .args("-Dspring.ai.mcp.server.transport=STDIO", "-Dspring.main.web-application-type=none", "-Dlogging.pattern.console=", "-jar", "target/mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar") .build(); // Initialize transport and client var transport = new StdioClientTransport(stdioParams); var client = McpClient.sync(transport).build();

TheClientStdio.javademonstrates how to implement an MCP client manually.

For a better development experience, consider using theMCP Client Boot Starters. These starters enable auto-configuration of multiple STDIO and/or SSE connections to MCP servers. See thestarter-default-clientandstarter-webflux-clientprojects for examples.

Use thestarter-default-clientto connect to the weatherstarter-stdio-server:
-

Follow thestarter-default-clientreadme instructions to build amcp-starter-default-client-0.0.1-SNAPSHOT.jarclient application.

Run the client using the configuration file:

java -Dspring.ai.mcp.client.stdio.connections.server1.command=java \ -Dspring.ai.mcp.client.stdio.connections.server1.args=-jar,/Users/christiantzolov/Dev/projects/spring-ai-examples/model-context-protocol/weather/starter-stdio-server/target/mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar \ -Dai.user.input='What is the weather in NY?' \ -Dlogging.pattern.console= \ -jar mcp-starter-default-client-0.0.1-SNAPSHOT.jar

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

{ "mcpServers": { "spring-ai-mcp-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-stdio-server-0.0.1-SNAPSHOT.jar" ] } } }

Replace/absolute/path/to/with the actual path to your built jar file.

All properties are prefixed withspring.ai.mcp.server:

# Required STDIO Configuration spring.main.web-application-type=none spring.main.banner-mode=off logging.pattern.console= # Server Configuration spring.ai.mcp.server.enabled=true spring.ai.mcp.server.name=my-weather-server spring.ai.mcp.server.version=0.0.1 # SYNC or ASYNC spring.ai.mcp.server.type=SYNC spring.ai.mcp.server.resource-change-notification=true spring.ai.mcp.server.tool-change-notification=true spring.ai.mcp.server.prompt-change-notification=true # Optional file logging logging.file.name=mcp-weather-stdio-server.log

- Disable web application type (spring.main.web-application-type=none)
- Disable Spring banner (spring.main.banner-mode=off)
- Clear console logging pattern (logging.pattern.console=)

- SYNC(default): UsesMcpSyncServerfor straightforward request-response patterns
- ASYNC: UsesMcpAsyncServerfor non-blocking operations with Project Reactor support

- Spring AI Documentation
-
MCP Server Boot Starter
-
MCP Client Boot Starter
-
Model Context Protocol Specification
-
Spring Boot Auto-configuration

Fetches precipitation forecast data for a specific location using the Buienradar service.

Access global weather data and forecasts using the OpenMeteo API, including current conditions, historical data, and location search.

Access weather station data, observations, and forecasts using the WeatherXM PRO API.

Integrates the Korea Meteorological Administration's public weather API to provide climate data.

GribStream MCP is a hosted Model Context Protocol server for weather forecast data. It helps AI agents discover GribStream datasets, resolve exact forecast variables and levels, validate request bodies, and build runnable GribStream Weather API requests for GFS, ECMWF IFS, NBM, HRRR, and other models.

Access meteorological data for Portugal from the IPMA public API using natural language.

62 real-time data tools for AI agents via MCP. Finance, crypto, FMCSA, sanctions, courts, weather, vehicles, cybersecurity. One bearer token, one bill. Free tier available.

Provides accurate Islamic prayer times for locations throughout Malaysia using the waktusolat.app API.

The Meteomatics MCP server allows AI agents to securely access Meteomatics weather data tools.

A production-clean MCP server for the free Open-Meteo weather API (geocoding, forecast, air quality) with SRE-grade rate limiting, backoff, and structured logging.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.