Weather MCP Server
A Model Context Protocol (MCP) server that provides weather information using the OpenWeatherMap API. This server primarily runs in stdio mode (the standard for MCP servers) with an experimental HTTP API mode for testing.
Features
MCP Protocol Support: Full stdio mode support for MCP clients
HTTP API Mode: Experimental simple HTTP API for testing
Current Weather: Get current weather conditions for any location
Weather Forecast: Get weather forecasts up to 5 days ahead
Location Flexibility: Support for city names, coordinates (lat,lon), and zip codes
Docker Support: Containerized deployment with docker-compose
Configurable: YAML-based configuration with environment variable support
Well Tested: Comprehensive test suite with pytest
Prerequisites
Python 3.11 or higher
OpenWeatherMap API key (free tier available at OpenWeatherMap)
Docker (optional, for containerized deployment)
Installation
Using pip
Using Docker
Configuration
The server uses a YAML configuration file (config.yaml) with the following structure:
Environment Variables
WEATHER_API_KEY: Your OpenWeatherMap API key (required)SERVER_MODE: Override server mode (optional, defaults to config file)
Usage
Running in stdio mode
Running in HTTP mode (Experimental)
Note: HTTP mode provides a simple REST API for testing. For production MCP usage, use stdio mode.
The HTTP server will start on http://localhost:8080 with the following endpoints:
GET /: Server informationGET /health: Health checkPOST /weather/current: Get current weather (JSON:{"location": "London"})POST /weather/forecast: Get forecast (JSON:{"location": "London", "days": 3})
Using with Docker
Stdio mode:
HTTP mode:
Available Tools
get_current_weather
Get current weather conditions for a location.
Parameters:
location(string, required): City name, coordinates (lat,lon), or zip code
Example:
Response includes:
Temperature and "feels like" temperature
Weather description
Humidity percentage
Atmospheric pressure
Wind speed
get_weather_forecast
Get weather forecast for a location up to 5 days ahead.
Parameters:
location(string, required): City name, coordinates (lat,lon), or zip codedays(integer, optional): Number of days to forecast (1-5, default: 3)
Example:
Response includes:
Forecast data in 3-hour intervals
Same weather details as current weather for each interval
Development
Running Tests
Code Structure
API Reference
OpenWeatherMap API
This server uses the OpenWeatherMap API. Key features:
Free Tier: 60 calls/minute, 1,000,000 calls/month
Current Weather: Real-time weather data
5-Day Forecast: Weather predictions in 3-hour intervals
Location Support: City names, coordinates, zip codes
Get your free API key at: https://openweathermap.org/api
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Troubleshooting
API Key Issues
If you see "API key not configured" errors:
Ensure
WEATHER_API_KEYenvironment variable is setCheck that the key is valid and active on OpenWeatherMap
Verify the key is not expired (free tier keys don't expire but can be revoked)
Connection Issues
If you encounter connection errors:
Check your internet connection
Verify OpenWeatherMap API is accessible from your location
Check if you've exceeded rate limits (60 calls/minute for free tier)
Docker Issues
If Docker containers fail to start:
Ensure Docker and docker-compose are installed
Check that port 8080 is not already in use (for HTTP mode)
Verify the API key is properly set in the environment
Support
For issues and questions:
Open an issue on GitHub: https://github.com/dangogh/weather-mcp/issues
Check existing issues for solutions