A comprehensive Model Context Protocol (MCP) server that provides weather information and forecasting capabilities using the Open-Meteo API.
This MCP server provides the following tools:
- π€οΈ Current Weather: Get real-time weather conditions for any location
- π Weather Forecast: Get multi-day weather forecasts (up to 7 days)
- π Location Search: Search for cities and locations to get coordinates
- ποΈ Weather by City: Get weather directly by city name
- π¨ Weather Alerts: Check for weather warnings and severe conditions
-
Install Python Dependencies:
pip install -r requirements.txt
-
Make the server executable (optional):
chmod +x weather_mcp_server.py
The MCP server can be run in several ways:
python weather_mcp_server.pymcp dev weather_mcp_server.py./weather_mcp_server.pyGet current weather conditions for specific coordinates.
Parameters:
latitude(float): Latitude coordinate (-90 to 90)longitude(float): Longitude coordinate (-180 to 180)
Example:
# Get current weather for New York City
get_current_weather(40.7128, -74.0060)Get weather forecast for a location.
Parameters:
latitude(float): Latitude coordinate (-90 to 90)longitude(float): Longitude coordinate (-180 to 180)days(int): Number of forecast days (1-7, default: 3)
Example:
# Get 5-day forecast for London
get_weather_forecast(51.5074, -0.1278, days=5)Search for locations by name to get coordinates.
Parameters:
query(str): Location name to search forlimit(int): Maximum results to return (1-10, default: 5)
Example:
# Search for Paris
search_location("Paris", limit=3)Get current weather for a city by name (combines location search + weather).
Parameters:
city_name(str): Name of the city
Example:
# Get weather for Tokyo
get_weather_by_city("Tokyo")Get weather alerts and warnings for a location.
Parameters:
latitude(float): Latitude coordinate (-90 to 90)longitude(float): Longitude coordinate (-180 to 180)
Example:
# Check alerts for Miami
get_weather_alerts(25.7617, -80.1918)The server uses the following optional environment variables:
LOG_LEVEL: Set logging level (default: INFO)REQUEST_TIMEOUT: HTTP request timeout in seconds (default: 30)
This server uses the Open-Meteo API, which:
- β Requires no API key
- β Is free to use
- β Provides accurate weather data
- β Has good global coverage
β οΈ Has rate limits for high usage
This MCP server is designed to work with AI models that support the Model Context Protocol. When integrated:
- Claude/GPT Integration: The AI can call weather tools naturally in conversation
- Automatic Location Resolution: Users can ask "What's the weather in Paris?" and the server handles location lookup
- Rich Formatting: Weather data is returned in human-readable format with emojis
- Error Handling: Graceful handling of network issues and invalid coordinates
User: "What's the weather like in Tokyo right now?"
AI: [Calls get_weather_by_city("Tokyo")]
User: "Give me a 5-day forecast for coordinates 40.7128, -74.0060"
AI: [Calls get_weather_forecast(40.7128, -74.0060, days=5)]
User: "Are there any weather alerts for Miami?"
AI: [Calls get_weather_alerts(25.7617, -80.1918)]
weather-mcp-server/
βββ weather_mcp_server.py # Main server implementation
βββ requirements.txt # Python dependencies
βββ README.md # This documentation
To extend the server with additional weather tools:
- Add new tool function with
@mcp.tool()decorator - Include proper type hints and docstrings
- Handle errors gracefully using the
make_request()helper - Format output consistently with emojis and clear structure
Test the server locally:
# Start in development mode
mcp dev weather_mcp_server.py
# Test individual tools
python -c "
import asyncio
from weather_mcp_server import get_current_weather
print(asyncio.run(get_current_weather(40.7128, -74.0060)))
"-
"Module not found" errors: Ensure all dependencies are installed
pip install -r requirements.txt
-
Network timeouts: Check internet connection and firewall settings
-
Invalid coordinates: Ensure latitude is between -90 and 90, longitude between -180 and 180
-
No location found: Try different search terms or check spelling
Enable debug logging for troubleshooting:
LOG_LEVEL=DEBUG python weather_mcp_server.pyThis project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
π€οΈ Happy weather forecasting! π€οΈ