๐ฆ๏ธ Weather MCP Server for Claude Integration
A production-ready Model Context Protocol (MCP) server built using the official Python MCP SDK that provides real-time weather information, forecasts, air quality, and weather alerts through the OpenWeatherMap API.
๐ Overview
This project demonstrates how to build a local MCP Server using the official Python MCP SDK. The server exposes multiple weather-related tools that can be consumed by any MCP-compatible client such as Claude Code, MCP Inspector, or other MCP hosts.
The server communicates with the OpenWeatherMap API and returns structured weather information through the MCP protocol.
โจ Features
- ๐ค๏ธ Current Weather
- ๐ 5-Day Weather Forecast
- ๐ช๏ธ Weather Alerts
- ๐ซ๏ธ Air Quality Index
- ๐ MCP Resources
- ๐ฌ MCP Prompt Templates
- ๐ Structured Logging
- โ ๏ธ Robust Error Handling
- ๐ Standard I/O (STDIO) Transport
- ๐๏ธ Clean Layered Architecture
๐๏ธ Architecture
User
โ
โผ
Claude Desktop
Claude Code
MCP Inspector
โ
โผ
MCP Protocol (STDIO)
โ
โผ
Weather MCP Server
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ
โผ โผ โผ
Tools Resources Prompts
โ
โผ
OpenWeatherMap REST API
โ
โผ
Weather Information
๐ Project Structure
weather-mcp/
โ
โโโ server.py
โโโ config.py
โโโ requirements.txt
โโโ README.md
โโโ .env.example
โ
โโโ models/
โ โโโ weather_model.py
โ โโโ forecast_model.py
โ
โโโ services/
โ โโโ parser.py
โ โโโ weather_api.py
โ
โโโ tools/
โ โโโ current_weather.py
โ โโโ forecast.py
โ โโโ alerts.py
โ โโโ air_quality.py
โ
โโโ prompts/
โ โโโ README.md
โ
โโโ resources/
โ โโโ README.md
โ
โโโ tests/
โ โโโ test_weather_parsing.py
โ
โโโ utils/
โโโ logger.py
โโโ helpers.py
โโโ exceptions.py
โ๏ธ Installation
Clone the repository
git clone https://github.com/PrasadMankar1309/Weather-MCP-Tool-for-the-Claude-Integration.git
cd Weather-MCP-Tool-for-the-Claude-Integration
Create a virtual environment
python -m venv .venv
Activate it
Windows
.venv\Scripts\activate
Linux / macOS
source .venv/bin/activate
Install dependencies
pip install -r requirements.txt
๐ Configuration
Create a .env file in the project root.
OPENWEATHER_API_KEY=your_api_key_here
OPENWEATHER_BASE_URL=https://api.openweathermap.org/data/2.5
REQUEST_TIMEOUT_SECONDS=10
LOG_LEVEL=INFO
You can obtain a free API key from:
https://openweathermap.org/api
โถ๏ธ Running the MCP Server
python server.py
The server communicates using the STDIO transport and is intended to be launched by an MCP-compatible client.
๐ Claude Desktop Integration
Example configuration:
{
"mcpServers": {
"weather": {
"command": "python",
"args": [
"C:/path/to/server.py"
]
}
}
}
Restart Claude Desktop after updating the configuration.
๐ Testing with MCP Inspector
Launch the MCP Inspector:
npx @modelcontextprotocol/inspector
Add a new STDIO server:
Command
python
Argument
server.py
If configured correctly, the Inspector will display:
- Tools
- Resources
- Prompts
๐ ๏ธ Available MCP Tools
| Tool | Description |
|---|---|
| Current Weather | Retrieves current weather for a city |
| Forecast | Retrieves weather forecast |
| Weather Alerts | Displays active weather alerts |
| Air Quality | Retrieves AQI information |
๐ MCP Resources
| Resource | Description |
|---|---|
| weather://supported-cities | Supported cities |
| weather://api-docs | API information |
| weather://prompt-examples | Example prompts |
๐ฌ MCP Prompt Templates
- Travel Weather Report
- Farmer Weather Report
- Weather Summary
๐ก Example Prompts
What's the weather in Pune?
Forecast for Mumbai
Weather alerts in Delhi
Air quality in London
๐ MCP Workflow
User Prompt
โ
โผ
Claude Desktop / Claude Code
โ
โผ
MCP Client
โ
โผ
Weather MCP Server
โ
โผ
OpenWeatherMap API
โ
โผ
JSON Response
โ
โผ
Claude Response
โ ๏ธ Error Handling
The server gracefully handles:
- Invalid city names
- Missing API keys
- Network failures
- Request timeouts
- API errors
๐ Future Improvements
- Hourly Forecast
- Weather Maps
- Geolocation Support
- Historical Weather
- Severe Weather Notifications
- Multi-language Support
- Docker Deployment
- Streamable HTTP Transport
๐งช Technologies Used
- Python 3.10
- Model Context Protocol (MCP)
- Official Python MCP SDK
- OpenWeatherMap API
- Dataclasses
- Logging
- dotenv
๐ค Contributing
Contributions are welcome!
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a Pull Request
๐ License
This project is licensed under the MIT License.
๐จโ๐ป Author
Prasad Mankar
โญ If you found this project useful, consider giving it a star!