Skip to main content

Weather MCP Tool for Claude Desktop - provides real-time weather data, forecasts, and historical weather information using the OpenWeatherMap API

Project description

Weather MCP Tool for Claude Desktop

An MCP (Model Context Protocol) tool that provides real-time weather data, forecasts, and historical weather information using the OpenWeatherMap API, specifically designed for Claude Desktop.

Tutorial

For a detailed guide on setting up and using this tool, check out our comprehensive Medium tutorial: Tutorial: Using Claude Desktop with Weather MCP Tool to Access Real-Time Weather Data Worldwide

Features

  • Real-time weather conditions for any location
  • Weather forecasts (up to 5 days)
  • Historical weather data (last 5 days)
  • Air quality information
  • Weather alerts and warnings
  • Location search functionality

Setup

  1. Ensure you have Python 3.10 or higher installed

  2. Install dependencies:

pip install -r requirements.txt
  1. Get an API key from OpenWeatherMap (free tier available)

    • Note: New API keys may take up to 24 hours to activate
  2. Set up environment variables for API key (recommended method):

    • Create a .env file in the project directory
    • Add your API key to the file:
    OPENWEATHER_API_KEY=your_openweathermap_api_key
    
    • Add .env to your .gitignore file to prevent committing sensitive data
  3. Update main.py to use the environment variable:

    # Add these imports at the top
    import os
    from dotenv import load_dotenv
    
    # Load environment variables
    load_dotenv()
    
    # Replace the API_KEY line with
    API_KEY = os.getenv("OPENWEATHER_API_KEY")
    

Integration with Claude Desktop

  1. Configure your MCP settings in Claude Desktop by adding the following to your MCP configuration:
{
  "mcpServers": {
    "weather-mcp": {
      "command": "py",
      "args": ["-3.13", "C:\\Path\\To\\Your\\Weather-MCP-ClaudeDesktop\\main.py"]
    }
  }
}
  1. Replace the path with the full path to your main.py file
  2. Run the server using:
py -3.13 main.py
  1. Keep the server running while using Claude Desktop

Available Tools

1. get_current_weather

Get real-time weather conditions for a location:

{
    "location": {
        "name": "New York",
        "country": "US",
        "lat": 40.7128,
        "lon": -74.006
    },
    "temperature": {
        "current": 25.6,
        "feels_like": 26.2,
        "min": 23.4,
        "max": 27.8
    },
    "weather_condition": {
        "main": "Clear",
        "description": "clear sky",
        "icon": "01d"
    },
    "wind": {
        "speed": 3.6,
        "deg": 220
    },
    "clouds": 5,
    "humidity": 65,
    "pressure": 1015,
    "visibility": 10000,
    "sunrise": "2025-03-16T06:12:34",
    "sunset": "2025-03-16T18:04:23",
    "timestamp": "2025-03-16T14:30:00"
}

2. get_weather_forecast

Get weather forecast for a location:

{
    "location": {
        "name": "London",
        "country": "GB",
        "lat": 51.5074,
        "lon": -0.1278
    },
    "forecast": [
        {
            "datetime": "2025-03-16T15:00:00",
            "temperature": {
                "temp": 18.2,
                "feels_like": 17.8,
                "min": 17.5,
                "max": 19.1
            },
            "weather_condition": {
                "main": "Rain",
                "description": "light rain",
                "icon": "10d"
            },
            "wind": {
                "speed": 4.2,
                "deg": 180
            },
            "clouds": 75,
            "humidity": 82,
            "pressure": 1010,
            "visibility": 8000,
            "pop": 0.4
        }
        // ... more forecast items
    ],
    "days": 5
}

3. get_air_quality

Get air quality data for a location:

{
    "location": {
        "name": "Beijing",
        "country": "CN",
        "lat": 39.9042,
        "lon": 116.4074
    },
    "air_quality_index": 3,
    "air_quality_level": "Moderate",
    "components": {
        "co": 250.34,
        "no": 0.5,
        "no2": 15.2,
        "o3": 140.8,
        "so2": 5.1,
        "pm2_5": 8.2,
        "pm10": 12.3,
        "nh3": 0.7
    },
    "timestamp": "2025-03-16T14:30:00"
}

4. get_historical_weather

Get historical weather data for a specific date:

{
    "location": {
        "name": "Paris",
        "country": "FR",
        "lat": 48.8566,
        "lon": 2.3522
    },
    "date": "2025-03-14",
    "temperature": {
        "temp": 20.3,
        "feels_like": 19.8
    },
    "weather_condition": {
        "main": "Clouds",
        "description": "scattered clouds",
        "icon": "03d"
    },
    "wind": {
        "speed": 2.8,
        "deg": 150
    },
    "clouds": 45,
    "humidity": 60,
    "pressure": 1012,
    "visibility": 10000,
    "sunrise": "2025-03-14T06:30:45",
    "sunset": "2025-03-14T18:15:22",
    "timestamp": "2025-03-14T12:00:00"
}

5. search_location

Search for locations by name:

{
    "results": [
        {
            "name": "Tokyo",
            "state": "",
            "country": "JP",
            "lat": 35.6762,
            "lon": 139.6503
        },
        {
            "name": "Tokyo",
            "state": "Tokyo",
            "country": "JP",
            "lat": 35.6895,
            "lon": 139.6917
        }
        // ... more results
    ]
}

6. get_weather_alerts

Get weather alerts for a location:

{
    "location": {
        "name": "Miami",
        "country": "US",
        "lat": 25.7617,
        "lon": -80.1918
    },
    "alerts": [
        {
            "sender": "NWS Miami",
            "event": "Heat Advisory",
            "start": "2025-03-16T12:00:00",
            "end": "2025-03-16T20:00:00",
            "description": "Heat index values between 105 and 110 expected",
            "tags": ["Extreme temperature value"]
        }
        // ... more alerts if any
    ],
    "alert_count": 1
}

Sample Queries

You can ask Claude Desktop questions like:

  • "What's the current weather in New York?"
  • "Show me the 5-day forecast for London"
  • "What's the air quality like in Beijing today?"
  • "How was the weather in Paris on March 14th?"
  • "Search for locations named 'Tokyo'"
  • "Are there any weather alerts for Miami?"
  • "Compare the current weather in Chicago, Miami, and Seattle"
  • "Show me a comparison of air quality in Beijing, Los Angeles, and Delhi"

Error Handling

All tools include proper error handling and will return an error message if something goes wrong:

{
    "error": "Failed to fetch current weather for InvalidLocation: Location not found"
}

Troubleshooting

If the MCP server is not working in Claude Desktop:

  1. Make sure the server is running - you should see output when you start the script
  2. Verify the path in your settings is correct and absolute
  3. Make sure Python 3.10+ is in your system PATH
  4. Check that all dependencies are installed
  5. Try restarting Claude Desktop
  6. Check logs for any error messages

Common API Issues

  • API Key Activation: New OpenWeatherMap API keys may take up to 24 hours to activate
  • Invalid API Key Error: If you get a 401 error, verify your API key is correct and active
  • Rate Limiting: Free tier allows up to 60 calls per minute, which might be exceeded during heavy usage

Rate Limits

This tool uses the OpenWeatherMap API which has rate limits. The free tier allows up to 60 calls per minute, which should be sufficient for personal use. Please be aware that very frequent requests may be throttled by the API.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_saintdoresh_weather_mcp_claudedesktop-0.1.0.tar.gz.

File metadata

File hashes

Hashes for iflow_mcp_saintdoresh_weather_mcp_claudedesktop-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b8bc7b201f06868c86902704c6174629af5b09ff66cb5e242247f084f691d2a
MD5 7ad9067e69577c7e14e985949c2d3573
BLAKE2b-256 b3477c5488e35aae65c51c6b1966c5e2d7fde01e455dba5c7b4d8825bd713d74

See more details on using hashes here.

File details

Details for the file iflow_mcp_saintdoresh_weather_mcp_claudedesktop-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for iflow_mcp_saintdoresh_weather_mcp_claudedesktop-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fac8671b7f692e9b32878f913a88921064e10d9ebbb81bcf92dff3a33498236a
MD5 8461e68055d1e797014e4687e02db8ad
BLAKE2b-256 6bb941049e2779555f792102914e79bb4141bab62b921cc1b99ea7f7467f0d71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page