mcp-server-weather

hardikralhan/mcp-server-weather

3.1

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.

Tools
5
Resources
0
Prompts
0

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
  • uv package manager (recommended) or pip

Setup

  1. Clone or download this project

    cd mcp-server-weather
    
  2. Create virtual environment

    uv venv
    .venv\Scripts\activate  # Windows
    # or
    source .venv/bin/activate  # Linux/Mac
    
  3. Install dependencies

    uv add "mcp[cli]"
    # or
    pip install -r requirements.txt
    
  4. Configure API keys (optional)

    Create a .env file in the project root:

    # For OpenWeatherMap (recommended)
    OPENWEATHER_API_KEY=your_openweather_api_key_here
    
    # For WeatherAPI (alternative)
    WEATHERAPI_KEY=your_weatherapi_key_here
    

    Note: 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)

  1. Visit OpenWeatherMap
  2. Sign up for a free account
  3. Get your API key from the dashboard
  4. Add to .env file: OPENWEATHER_API_KEY=your_key_here

WeatherAPI (Alternative)

  1. Visit WeatherAPI
  2. Sign up for a free account
  3. Get your API key from the dashboard
  4. Add to .env file: 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 name
  • temperature: Temperature in Celsius
  • humidity: Humidity percentage
  • pressure: Atmospheric pressure in hPa
  • wind_speed: Wind speed in m/s
  • wind_direction: Wind direction
  • description: Weather description
  • icon: Weather icon code
  • timestamp: Data timestamp
  • feels_like: Feels-like temperature
  • visibility: Visibility in km
  • uv_index: UV index

ForecastData

  • date: Forecast date
  • temperature_max: Maximum temperature
  • temperature_min: Minimum temperature
  • description: Weather description
  • icon: Weather icon code
  • humidity: Humidity percentage
  • wind_speed: Wind speed in m/s
  • precipitation_chance: Precipitation probability

WeatherAlert

  • title: Alert title
  • description: Alert description
  • severity: Alert severity level
  • start_time: Alert start time
  • end_time: Alert end time
  • areas_affected: Affected areas

VS Code Integration

  1. Open the project folder in VS Code
  2. Run the server:
    uv run main.py
    
  3. Press Ctrl+Shift+I to open the chat
  4. Login with GitHub and configure MCP settings
  5. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For issues and questions:

Changelog

v1.0.0

  • Initial release
  • Complete weather tools and resources
  • Support for multiple weather APIs
  • Comprehensive error handling
  • Mock data fallback for testing