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.
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.
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
Ensure you have Python 3.10 or higher installed
Install dependencies:
pip install -r requirements.txt
Get an API key from OpenWeatherMap (free tier available)
Set up environment variables for API key (recommended method):
.env
file in the project directoryOPENWEATHER_API_KEY=your_openweathermap_api_key
.env
to your .gitignore
file to prevent committing sensitive dataUpdate 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")
{
"mcpServers": {
"weather-mcp": {
"command": "py",
"args": ["-3.13", "C:\\Path\\To\\Your\\Weather-MCP-ClaudeDesktop\\main.py"]
}
}
}
py -3.13 main.py
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"
}
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
}
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"
}
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"
}
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
]
}
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
}
You can ask Claude Desktop questions like:
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"
}
If the MCP server is not working in Claude Desktop:
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.
MIT License