experiment-java-mcp-server
The project is a Spring Boot application that provides weather information using the Model Context Protocol (MCP). It offers mock weather data for AI assistants and is designed for easy setup and integration.
Weather MCP Server
A Spring Boot application that provides weather information through the Model Context Protocol (MCP). This project demonstrates how to create an MCP server using Spring AI to expose weather data as a tool that can be used by AI assistants.
š Table of Contents
- Overview
- Features
- Technologies
- Project Structure
- Prerequisites
- Installation
- Running the Application
- Using the MCP Inspector
- API Documentation
- Contributing
- License
š Overview
This project implements a weather service that provides mock weather data for different locations. It exposes this functionality through the Model Context Protocol (MCP), allowing AI assistants to retrieve weather information for specified locations.
⨠Features
- Get current weather information for any location
- Mock weather data generation with realistic parameters
- MCP integration for AI assistant compatibility
- Spring Boot application with easy setup and configuration
š ļø Technologies
- Java 17
- Spring Boot 3.2.0
- Spring AI MCP Server
- Maven
- Lombok
š Project Structure
src/
āāā main/
ā āāā java/
ā ā āāā com/
ā ā āāā gox/
ā ā āāā weather/
ā ā āāā WeatherMcpApplication.java # Main application class
ā ā āāā model/
ā ā ā āāā WeatherData.java # Weather data model
ā ā āāā service/
ā ā āāā WeatherService.java # Weather service with MCP tool
ā āāā resources/
ā āāā application.properties # Application configuration
š Prerequisites
- Java 17 or higher
- Maven 3.6 or higher
- Node.js and npm (for MCP Inspector)
š Installation
-
Clone the repository:
git clone https://github.com/yourusername/weather-mcp-java.git cd weather-mcp-java
-
Build the project:
mvn clean install
šāāļø Running the Application
Start the Spring Boot application:
mvn spring-boot:run
The application will start on port 8080 by default (configurable in application.properties
).
āļø Configuring MCP in IDE Tools
To use this MCP server with AI assistants in IDE tools like Cursor or Cline:
- Open your IDE's settings for AI assistant configuration
- Look for MCP or Model Context Protocol settings
- Add a new MCP server with the following SSE endpoint:
http://localhost:8089/sse
- Save the settings and restart the AI assistant if necessary
- The weather tool should now be available to your AI assistant
Note: Make sure the port (8089) matches the port configured in your application.properties
file.
š§ Using the MCP Inspector
The MCP Inspector is a tool that allows you to test and debug your MCP server (If you want to debug MCP server). To use it:
-
Install and run the MCP Inspector:
npx @modelcontextprotocol/inspector
-
Open the MCP Inspector in your browser:
http://127.0.0.1:6274/#tools
-
Connect to your MCP server by entering the SSE endpoint:
http://localhost:8080/mcp/sse
Note: The port (8080) should match the port your Spring Boot application is running on.
-
Once connected, you can test the
getWeather
tool by providing a location parameter.
š API Documentation
Weather Service
The Weather Service provides the following functionality:
Get Weather
Returns weather information for a specified location.
Tool Name: getWeather
Parameters:
location
(String): The name of the location to get weather for (e.g., "New York", "London", "Tokyo")
Response:
{
"location": "New York",
"temperature": 22.5,
"condition": "Partly Cloudy",
"humidity": 65,
"windSpeed": 12.3
}
š¤ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
š License
This project is licensed under the MIT License - see the LICENSE file for details.