Anique-1/weather-mcp-server
If you are the rightful owner of weather-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.
This Weather MCP Server provides weather and air quality data using FastMCP and integrates with WeatherAPI.
Weather MCP Server
This project is a Weather Server built with FastMCP, providing weather and air quality data via MCP tools. It integrates with the WeatherAPI to offer current weather, forecasts, historical data, air quality, and location search.
Features
- Current Weather: Get real-time weather conditions for any location.
- Weather Forecast: Retrieve weather forecasts for up to 10 days.
- Weather History: Access historical weather data for a specific date (up to 7 days in the past for free tier).
- Air Quality: Get detailed air quality metrics for a location.
- Location Search: Search for locations matching a query.
MCP Tools
The following MCP tools are available:
-
get_current_weather(location: str) -> str
Returns current weather conditions for the specified location. -
get_weather_forecast(location: str, days: int = 3) -> str
Returns a weather forecast for the specified location and number of days (1-10). -
get_weather_history(location: str, date: str) -> str
Returns historical weather data for the specified location and date (YYYY-MM-DD). -
search_locations(query: str) -> str
Searches for locations matching the query string. -
get_air_quality(location: str) -> str
Returns air quality data for the specified location.
Requirements
Setup
-
Install dependencies
Install required packages using pip:pip install httpx fastmcp
-
Set the WeatherAPI key
Obtain an API key from WeatherAPI and set it as an environment variable:set WEATHER_API_KEY=your_api_key_here
(On Linux/macOS, use
export WEATHER_API_KEY=your_api_key_here
) -
Run the server
Start the MCP server:python main.py
File Descriptions
-
main.py
Main server script. Defines all MCP tools and handles requests to the WeatherAPI. -
.gitignore
Specifies files and directories to be ignored by Git.
Example Usage
You can use the MCP tools programmatically or via an MCP client. Example tool usage:
# Example: Get current weather for London
result = await get_current_weather("London")
print(result)
License
This project is provided for educational purposes. See WeatherAPI Terms for API usage restrictions.