zuramai/mcp-weather-rs
If you are the rightful owner of mcp-weather-rs and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This repository contains a Rust implementation of a Model Context Protocol (MCP) server that provides weather forecasting capabilities using the Open-Meteo API.
get_forecast
Accepts latitude and longitude coordinates and returns weather information.
Rust MCP Server Weather
This repository contains a Rust implementation of a Model Context Protocol (MCP) server that provides weather forecasting capabilities. The server integrates with the Open-Meteo API to fetch real-time weather data based on geographic coordinates.
Features
- Weather Forecasting: Get current weather conditions and hourly forecasts
- Geographic Coordinates: Query weather data using latitude and longitude
- MCP Integration: Compatible with Model Context Protocol for AI assistant integration
- Real-time Data: Fetches live weather data from Open-Meteo API
- Structured Output: Returns formatted weather information including temperature, humidity, and wind speed
Installation
Prerequisites
- Rust (latest stable version)
- Cargo package manager
Building from Source
- Clone the repository:
git clone https://github.com/yourusername/mcp-weather.git
cd mcp-weather
- Build the project:
cargo build --release
- The binary will be available at
target/release/mcp-weather
Usage
Running the MCP Server
Start the weather MCP server:
cargo run
Debugging the MCP Server
Start the weather MCP server with npx @modelcontextprotocol/inspector:
npx @modelcontextprotocol/inspector cargo run
The server will start and listen for MCP protocol messages via standard input/output.
MCP Tool: get_forecast
The server provides a get_forecast
tool that accepts latitude and longitude coordinates and returns weather information.
Parameters:
latitude
(f32): Geographic latitude coordinatelongitude
(f32): Geographic longitude coordinate
Example Response:
Current Weather:
Temperature: 22.5°C
Wind Speed: 15.2 km/h
Hourly Forecast:
- 14:00: 23.1°C, 65% humidity, 12.8 km/h wind
- 15:00: 24.2°C, 62% humidity, 14.1 km/h wind
...
API Integration
This MCP server integrates with the Open-Meteo API, a free weather API that provides:
- Current weather conditions
- Hourly forecasts
- Temperature, humidity, and wind speed data
- No API key required
Development
Project Structure
src/
āāā main.rs # Application entry point
āāā service.rs # MCP service implementation
āāā model.rs # Data structures and API models
āāā util.rs # Utility functions
āāā error.rs # Error handling
Dependencies
rmcp
: Rust MCP SDK for server implementationreqwest
: HTTP client for API requestsserde
: Serialization/deserializationtokio
: Async runtimetracing
: Logging and diagnostics
Adding New Features
To extend the weather service:
- Add new tools in
service.rs
using the#[tool]
attribute - Define request/response models in
model.rs
- Implement utility functions in
util.rs
- Update error handling in
error.rs
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the file for details.
Acknowledgments
- Open-Meteo for providing free weather data
- Model Context Protocol for the MCP specification
- Rust MCP SDK for the Rust implementation