dorianlgs/WeatherMCP
If you are the rightful owner of WeatherMCP 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.
WeatherMCP is a high-performance Model Context Protocol (MCP) server for weather data, implemented in Go, providing real-time weather alerts and forecasts using the National Weather Service (NWS) API.
get_alerts
Get active weather alerts for a US state.
get_forecast
Get weather forecast for a location using coordinates.
WeatherMCP š¤ļø
A high-performance Model Context Protocol (MCP) server for weather data, implemented in Go. This server provides real-time weather alerts and forecasts using the National Weather Service (NWS) API.
Features
- š¦ļø Weather Alerts: Get active weather alerts for any US state
- š Weather Forecasts: Get detailed forecasts for any location using coordinates
- ā” High Performance: Built with caching, retry logic, and connection pooling
- š§ Configurable: Environment-based configuration with sensible defaults
- š³ Containerized: Docker support for easy deployment
- š Monitoring: Structured logging and health checks
- š”ļø Robust: Input validation, error handling, and graceful shutdown
Quick Start
Prerequisites
- Go 1.24 or later
- Git
Installation
-
Clone the repository
git clone https://github.com/dorianlgs/WeatherMCP.git cd WeatherMCP
-
Install dependencies
go mod download
-
Build the application
make build # or go build -o WeatherMCP .
-
Run in stdio mode (default)
./WeatherMCP
-
Run in SSE mode
./WeatherMCP -t sse
Configuration
The application can be configured using environment variables:
Variable | Default | Description |
---|---|---|
NWS_API_BASE | https://api.weather.gov | NWS API base URL |
USER_AGENT | weather-mcp/2.0.0 | User agent for API requests |
HTTP_TIMEOUT | 30s | HTTP request timeout |
PORT | 8080 | Port for SSE server |
CACHE_TTL | 5m | Cache time-to-live |
MAX_RETRIES | 3 | Maximum retry attempts |
ENABLE_CACHING | true | Enable response caching |
LOG_LEVEL | info | Log level (debug, info, warn, error) |
Example Configuration
export LOG_LEVEL=debug
export ENABLE_CACHING=true
export CACHE_TTL=10m
export MAX_RETRIES=5
Usage
MCP Tools
The server provides two main tools:
1. get_alerts
- Weather Alerts
Get active weather alerts for a US state.
Parameters:
state
(string, required): Two-letter US state code (e.g., "CA", "NY", "TX")
Example:
{
"name": "get_alerts",
"arguments": {
"state": "CA"
}
}
2. get_forecast
- Weather Forecast
Get weather forecast for a location using coordinates.
Parameters:
latitude
(number, required): Latitude between -90 and 90longitude
(number, required): Longitude between -180 and 180
Example:
{
"name": "get_forecast",
"arguments": {
"latitude": 37.7749,
"longitude": -122.4194
}
}
Claude Desktop Configuration
Add this to your claude_desktop_config.json
:
{
"mcpServers": {
"weather-mcp-stdio": {
"command": "/path/to/WeatherMCP",
"args": [],
"env": {
"LOG_LEVEL": "info",
"ENABLE_CACHING": "true"
}
},
"weather-mcp-sse": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8080/sse"
]
}
}
}
Development
Using Make
The project includes a comprehensive Makefile for common tasks:
# Build the application
make build
# Run tests
make test
# Run with coverage
make test-coverage
# Format code
make fmt
# Run linter
make lint
# Build for all platforms
make build-all
# Clean build artifacts
make clean
# Show all available commands
make help
Using Docker
Quick Start with Docker
# Build and run in stdio mode
docker-compose --profile stdio up
# Build and run in SSE mode
docker-compose --profile sse up
# Development mode with hot reload
docker-compose --profile dev up
Manual Docker Commands
# Build the image
docker build -t weather-mcp .
# Run in stdio mode
docker run weather-mcp
# Run in SSE mode
docker run -p 8080:8080 weather-mcp -t sse
# Run with custom environment
docker run -e LOG_LEVEL=debug -e ENABLE_CACHING=false weather-mcp
Testing
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run specific test
go test -v -run TestWeatherAlertHandler
# Run benchmarks
go test -bench=. -benchmem ./...
MCP Inspector
Test the server using the MCP Inspector:
# Install MCP Inspector
npm install -g @modelcontextprotocol/inspector
# Run inspector
npx @modelcontextprotocol/inspector
# Or use Docker Compose
docker-compose --profile inspector up
Architecture
Project Structure
WeatherMCP/
āāā main.go # Application entry point and server setup
āāā config.go # Configuration management
āāā handlers.go # MCP tool handlers
āāā structures.go # Data structures and models
āāā utils.go # Utilities, HTTP client, and caching
āāā Makefile # Build and development tasks
āāā Dockerfile # Container configuration
āāā docker-compose.yml # Multi-service deployment
āāā go.mod # Go module definition
āāā go.sum # Dependency checksums
āāā .gitignore # Git ignore rules
āāā README.md # This file
Key Components
- Configuration Management: Environment-based configuration with validation
- HTTP Client: Robust client with retry logic, caching, and connection pooling
- Caching: In-memory caching with TTL for API responses
- Error Handling: Comprehensive error handling with meaningful messages
- Input Validation: Strict validation for all input parameters
- Logging: Structured logging with configurable levels
Performance Features
- Caching: Configurable TTL-based caching reduces API calls
- Connection Pooling: Reuses HTTP connections for better performance
- Retry Logic: Exponential backoff for failed requests
- Graceful Shutdown: Proper cleanup on server termination
- Memory Efficient: Minimal memory footprint with proper cleanup
API Reference
National Weather Service API
The application uses the National Weather Service (NWS) API:
- Base URL:
https://api.weather.gov
- Format: GeoJSON
- Rate Limits: 1000 requests per hour per IP
- Documentation: NWS API Documentation
Endpoints Used
- Alerts:
/alerts/active/area/{state}
- Points:
/points/{lat},{lon}
- Forecast: Dynamic URL from points response
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
Development Guidelines
- Follow Go best practices and conventions
- Add tests for new functionality
- Update documentation for API changes
- Use meaningful commit messages
- Ensure all tests pass before submitting PR
License
This project is licensed under the MIT License - see the file for details.
Acknowledgments
- National Weather Service for providing the weather API
- MCP Go SDK for the MCP implementation
- Model Context Protocol for the protocol specification
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Wiki
Changelog
v2.0.0
- Complete rewrite with improved architecture
- Added caching and retry logic
- Enhanced error handling and validation
- Docker and Docker Compose support
- Comprehensive testing and documentation
- Performance optimizations
v1.0.0
- Initial release with basic weather alerts and forecasts
- Stdio and SSE transport support