hardikralhan/mcp-server-weather
If you are the rightful owner of mcp-server-weather and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
Weather MCP Server provides real-time weather data, forecasts, alerts, and analysis tools for LLM applications.
Weather MCP Server 🌤️
A comprehensive weather service for Model Context Protocol (MCP) that provides real-time weather data, forecasts, alerts, and analysis tools for LLM applications.
Features
🛠️ Tools
- get_current_weather: Get real-time weather conditions for any location
- get_weather_forecast: Get multi-day weather forecasts (1-10 days)
- get_weather_alerts: Get active weather warnings and alerts
- compare_weather: Compare weather conditions between two locations
- get_weather_summary: Get comprehensive weather summaries with current conditions and forecast
📚 Resources
- weather://current/{location}: Current weather data resource
- weather://forecast/{location}: Weather forecast resource
- weather://alerts/{location}: Weather alerts resource
- weather://info: Service information and capabilities
💬 Prompts
- weather_analysis_prompt: Generate weather analysis prompts
- weather_comparison_prompt: Compare weather between locations
- weather_planning_prompt: Plan activities based on weather
Installation
Prerequisites
- Python 3.8 or higher
uvpackage manager (recommended) orpip
Setup
-
Clone or download this project
cd mcp-server-weather -
Create virtual environment
uv venv .venv\Scripts\activate # Windows # or source .venv/bin/activate # Linux/Mac -
Install dependencies
uv add "mcp[cli]" # or pip install -r requirements.txt -
Configure API keys (optional)
Create a
.envfile in the project root:# For OpenWeatherMap (recommended) OPENWEATHER_API_KEY=your_openweather_api_key_here # For WeatherAPI (alternative) WEATHERAPI_KEY=your_weatherapi_key_hereNote: The server works with mock data if no API keys are provided, perfect for testing and development.
Usage
Development Mode (with MCP Inspector)
uv run mcp dev main.py
Normal Mode
uv run mcp run
Direct Execution
uv run main.py
Install in Claude Desktop
uv run mcp install main.py
API Keys Setup
OpenWeatherMap (Recommended)
- Visit OpenWeatherMap
- Sign up for a free account
- Get your API key from the dashboard
- Add to
.envfile:OPENWEATHER_API_KEY=your_key_here
WeatherAPI (Alternative)
- Visit WeatherAPI
- Sign up for a free account
- Get your API key from the dashboard
- Add to
.envfile:WEATHERAPI_KEY=your_key_here
Examples
Using Tools
# Get current weather
await get_current_weather("London, UK")
# Get 5-day forecast
await get_weather_forecast("New York, NY", days=5)
# Get weather alerts
await get_weather_alerts("Miami, FL")
# Compare weather between cities
await compare_weather("Tokyo, Japan", "Sydney, Australia")
# Get comprehensive weather summary
await get_weather_summary("Paris, France")
Using Resources
# Current weather resource
weather://current/London,UK
# Forecast resource
weather://forecast/New York,NY
# Alerts resource
weather://alerts/Miami,FL
# Service info
weather://info
Using Prompts
# Weather analysis
await weather_analysis_prompt("San Francisco, CA", "comprehensive")
# Weather comparison
await weather_comparison_prompt("London, UK", "New York, NY")
# Activity planning
await weather_planning_prompt("Seattle, WA", "hiking", days_ahead=3)
Data Models
WeatherData
location: Location nametemperature: Temperature in Celsiushumidity: Humidity percentagepressure: Atmospheric pressure in hPawind_speed: Wind speed in m/swind_direction: Wind directiondescription: Weather descriptionicon: Weather icon codetimestamp: Data timestampfeels_like: Feels-like temperaturevisibility: Visibility in kmuv_index: UV index
ForecastData
date: Forecast datetemperature_max: Maximum temperaturetemperature_min: Minimum temperaturedescription: Weather descriptionicon: Weather icon codehumidity: Humidity percentagewind_speed: Wind speed in m/sprecipitation_chance: Precipitation probability
WeatherAlert
title: Alert titledescription: Alert descriptionseverity: Alert severity levelstart_time: Alert start timeend_time: Alert end timeareas_affected: Affected areas
VS Code Integration
- Open the project folder in VS Code
- Run the server:
uv run main.py - Press
Ctrl+Shift+Ito open the chat - Login with GitHub and configure MCP settings
- Add the server configuration to your VS Code settings
Project Structure
mcp-server-weather/
├── main.py # Main MCP server implementation
├── weather_service.py # Weather service and API integration
├── pyproject.toml # Project configuration
├── requirements.txt # Python dependencies
├── README.md # This file
├── .env # Environment variables (create this)
└── .gitignore # Git ignore file
Error Handling
The server includes comprehensive error handling:
- Graceful fallback to mock data when APIs are unavailable
- Detailed error messages for debugging
- Context-aware logging for development
- Automatic retry mechanisms for API calls
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions:
- Check the MCP Documentation
- Review the Python SDK Documentation
- Open an issue in this repository
Changelog
v1.0.0
- Initial release
- Complete weather tools and resources
- Support for multiple weather APIs
- Comprehensive error handling
- Mock data fallback for testing