dinesh207/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.
A Model Context Protocol (MCP) server that provides weather data through the Open-Meteo API.
get_current_weather
Fetches current weather data for a specified location using latitude and longitude.
Weather MCP Server
A Model Context Protocol (MCP) server that provides weather data through the Open-Meteo API. This server allows AI agents and applications to fetch current weather information for any location using latitude and longitude coordinates.
Features
- š¤ļø Real-time Weather Data: Get current weather conditions for any location
- š Coordinate-based Lookup: Use latitude and longitude for precise location targeting
- š Async Operations: Built with async/await for efficient API calls
- š”ļø Error Handling: Robust error handling with graceful fallbacks
- š Comprehensive Data: Includes temperature, precipitation, weather codes, and more
Prerequisites
- Python 3.13 or higher
uv
package manager (recommended) orpip
Installation
-
Clone or navigate to the project directory:
cd weather_mcp_Server
-
Install dependencies using uv:
uv sync
Or using pip:
pip install -r requirements.txt
Usage
Running the Server
Start the MCP server:
python server.py
The server will start and listen for MCP protocol messages via stdio transport.
Available Tools
get_current_weather
Fetches current weather data for a specified location.
Parameters:
latitude
(float): Latitude coordinate of the locationlongitude
(float): Longitude coordinate of the location
Returns:
dict[str, Any]
: Weather data including:- Hourly data: temperature, precipitation, weather codes
- Daily data: max/min temperatures, precipitation sums
- Timezone information
Example Usage:
# Get weather for New York City (40.7128, -74.0060)
weather_data = await get_current_weather(40.7128, -74.0060)
API Integration
This server integrates with the Open-Meteo API, a free weather API that provides:
- No API Key Required: Free to use with reasonable rate limits
- Global Coverage: Weather data for locations worldwide
- Multiple Data Points: Temperature, precipitation, wind, pressure, and more
- High Accuracy: Based on multiple weather models
API Endpoints Used
- Forecast Endpoint:
https://api.open-meteo.com/v1/forecast
- Parameters: latitude, longitude, hourly/daily variables, timezone
Project Structure
weather_mcp_Server/
āāā server.py # Main MCP server with tool definitions
āāā weather_api_client.py # Open-Meteo API client utilities
āāā pyproject.toml # Project dependencies and metadata
āāā uv.lock # Lock file for dependency versions
āāā README.md # This file
Dependencies
- httpx: Async HTTP client for API requests
- mcp[cli]: Model Context Protocol server implementation
- Python 3.13+: Modern Python features and type hints
Development
Adding New Tools
To add new weather-related tools:
- Create the tool function in
server.py
ortools.py
- Decorate with
@mcp.tool()
- Define proper type hints for parameters and return values
- Add comprehensive docstrings
Example:
@mcp.tool()
async def get_weather_forecast(latitude: float, longitude: float, days: int = 7) -> dict[str, Any]:
"""Get weather forecast for the next N days."""
# Implementation here
pass
Error Handling
The server includes robust error handling:
- API Timeouts: 30-second timeout for API requests
- Network Errors: Graceful handling of connection issues
- Invalid Data: Fallback responses for malformed data
- User-Agent: Proper identification for API requests
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is open source. Please check the license file for details.
Support
For issues or questions:
- Check the Open-Meteo API documentation
- Review the MCP protocol documentation
- Open an issue in the project repository
Note: This server is designed to work with MCP-compatible clients and agents. Make sure your client supports the MCP protocol for proper integration.