my -stdio
Spring AI MCP Weather STDIO Server - A Spring Boot starter project demonstrating how to build a Model Context Protocol (MCP) server that provides weather-related tools
claude mcp add --transport stdio cloud4java-my-mcp-stdio-server java -Dspring.ai.mcp.server.stdio=true -Dspring.main.web-application-type=none -Dlogging.pattern.console= -jar /absolute/path/to/my-mcp-stdio-server-0.0.1-SNAPSHOT.jar
How to use
This MCP server implements a weather-focused tool suite exposed via the MCP (Model Context Protocol) using a STDIO transport. It is built with the Spring AI MCP Server Boot Starter, automatically registering tools defined as Spring beans and enabling both synchronous and asynchronous operation modes as configured. The provided WeatherService exposes tools such as a weather forecast tool (by latitude/longitude) and a weather alerts tool (by US state), which can be invoked by an MCP client over STDIO. Typical usage involves starting the server JAR (which is usually launched by the client in STDIO mode) and then using an MCP client to call the registered tools and receive structured results or descriptions of forecast data, alerts, and related weather information.
To use the tools, initialize an MCP client that connects via STDIO to the running server. You can call the tools by their registered names, for example calling getWeatherForecastBrazil with latitude and longitude, or getAlerts with a state code. The client will receive responses that include details such as temperature, wind, forecast description, or alert event types and severities. The starter demonstrates how to define tool methods using the @Tool annotation and how to expose them to the MCP server through ToolCallbacks, enabling seamless integration with the MCP ecosystem.
How to install
Prerequisites
- Java 17 or later
- Maven 3.6 or later
- Optional: Claude Desktop for integration with the Claude assistant
- Install Java and Maven
- Ensure JDK 17+ is installed and available on your PATH
- Verify: java -version mvn -version
- Build the MCP server JAR
-
From the project root, run:
./mvnw clean install -DskipTests
This generates the server JAR (e.g., target/my-mcp-stdio-server-0.0.1-SNAPSHOT.jar).
- Run or prepare STDIO transport
- The server is designed to be driven by a STDIO client. Ensure the client is configured to start the server in STDIO mode (the typical pattern is to launch the server JAR with STDIO transport enabled and stdout/stderr wired to the client).
- (Optional) Claude Desktop integration
- If using Claude Desktop, configure the mcpServers section with the path to your built jar as shown in the README example.
Notes
- The configuration uses STDIO mode, so web UI and HTTP endpoints may be disabled by setting spring.main.web-application-type=none.
- You can customize server name, version, and notification settings via application properties as described in the README.
Additional notes
Tips and common issues:
- Ensure STDIO is enabled for both the server and the client; the server relies on STDIO transport for tool invocation.
- When wiring via Claude Desktop, use absolute paths to the built JAR and ensure the Java command includes the appropriate -D properties to enable STDIO transport.
- If the client cannot connect, verify the server JAR path and confirm that the client process has access to start the server in STDIO mode.
- Review the properties under spring.ai.mcp.server.* to control synchronization (SYNC) vs asynchronous (ASYNC) behavior, and enable/disable change notifications as needed.
- The WeatherService demonstrates how to declare tools with @Tool and aggregate ToolCallbacks into the MCP server during auto-configuration.
- For debugging, check console logs and ensure logging pattern is cleared for STDIO integration (logging.pattern.console=).