Enables secure storage and loading of the OpenWeatherMap API key through environment variables, keeping sensitive data out of the codebase.
Offers a comprehensive tutorial on setting up and using the Weather MCP Tool with Claude Desktop, published on the Medium platform.
Requires Python 3.10+ as the runtime environment for the MCP server that processes weather data requests.
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
Related MCP server: Weather MCP Server
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
Ensure you have Python 3.10 or higher installed
Install dependencies:
Get an API key from OpenWeatherMap (free tier available)
Note: New API keys may take up to 24 hours to activate
Set up environment variables for API key (recommended method):
Create a
.envfile in the project directoryAdd your API key to the file:
OPENWEATHER_API_KEY=your_openweathermap_api_keyAdd
.envto your.gitignorefile to prevent committing sensitive data
Update
main.pyto 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
Configure your MCP settings in Claude Desktop by adding the following to your MCP configuration:
Replace the path with the full path to your main.py file
Run the server using:
Keep the server running while using Claude Desktop
Available Tools
1. get_current_weather
Get real-time weather conditions for a location:
2. get_weather_forecast
Get weather forecast for a location:
3. get_air_quality
Get air quality data for a location:
4. get_historical_weather
Get historical weather data for a specific date:
5. search_location
Search for locations by name:
6. get_weather_alerts
Get weather alerts for a location:
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:
Troubleshooting
If the MCP server is not working in Claude Desktop:
Make sure the server is running - you should see output when you start the script
Verify the path in your settings is correct and absolute
Make sure Python 3.10+ is in your system PATH
Check that all dependencies are installed
Try restarting Claude Desktop
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