AI-General/MCP-Server
If you are the rightful owner of MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Python-based Model Context Protocol (MCP) server that provides weather data and alerts for the United States using the National Weather Service (NWS) API.
Weather MCP Server
A Python-based Model Context Protocol (MCP) server that provides weather data and alerts for the United States using the National Weather Service (NWS) API.
Features
- Get Active Weather Alerts: Retrieve current weather alerts for any US state by its two-letter abbreviation.
- Get Weather Forecast: Fetch detailed weather forecasts for any location in the US using latitude and longitude.
- FastMCP Integration: Built on top of the FastMCP framework for easy integration with MCP clients.
Requirements
- Python 3.8+
- httpx
- mcp-server (with FastMCP)
Install dependencies with:
pip install -r requirements.txt
Or, if you use pyproject.toml
:
pip install .
Usage
Running the Server
You can start the MCP server using:
python weather.py
The server will run using the stdio
transport by default.
Tools Provided
1. Get Weather Alerts
Fetches active weather alerts for a given US state.
- Function:
get_alerts(state: str)
- Parameters:
state
: Two-letter state abbreviation (e.g.,CA
,NY
)
- Returns: Formatted string of active alerts or a message if none are active.
2. Get Weather Forecast
Fetches a weather forecast for a given latitude and longitude.
- Function:
get_forecast(latitude: float, longitude: float)
- Parameters:
latitude
: Latitude of the locationlongitude
: Longitude of the location
- Returns: Formatted string with the next 5 forecast periods.
Example
from weather import get_alerts, get_forecast
# Get alerts for California
alerts = await get_alerts('CA')
print(alerts)
# Get forecast for San Francisco, CA
forecast = await get_forecast(37.7749, -122.4194)
print(forecast)
API Reference
This server uses the National Weather Service API for all weather data.
License
This project is licensed under the MIT License.