OriShmila/weather-api-mcp-server
If you are the rightful owner of weather-api-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 comprehensive Model Context Protocol (MCP) server for weather data with bulletproof schema validation.
Weather API MCP Server
A comprehensive Model Context Protocol (MCP) server for weather data with bulletproof schema validation. Built with the standard MCP framework and featuring explicit tool schemas, comprehensive testing, and full input/output validation.
๐ Features
Weather Tools
- Current weather conditions - Real-time weather with optional air quality
- Weather forecasts - 1-14 day forecasts with alerts and air quality
- Weather alerts - Severe weather warnings and advisories
- Air quality information - Pollution levels and health indices
- Astronomy data - Sunrise, sunset, moon phases, and solar/lunar positions
- Location search - Find and identify locations by name, coordinates, postal codes, or airport codes
- Timezone information - Time zone data for any location
- Sports events - Weather for sporting events (football, cricket, golf)
Advanced Features
- ๐ Comprehensive Schema Validation - Full JSON Schema validation for inputs and outputs
- ๐ Explicit Tool Definitions - All tools defined in
tools.json
with complete schemas - ๐งช Extensive Testing - 45+ test cases covering all tools and edge cases
- โก High Performance - 100% success rate with optimized API calls
- ๐ก๏ธ Error Handling - Robust validation and meaningful error messages
- ๐ Real-time Validation - Input parameters validated before API calls
๐ Available Tools
Tool | Description | Required Parameters | Optional Parameters |
---|---|---|---|
get_current_weather | Current weather conditions | query | include_air_quality |
get_weather_forecast | Weather forecasts (1-14 days) | query | days , include_air_quality , include_alerts |
get_weather_alerts | Weather warnings and alerts | query | - |
get_weather_airquality | Air quality measurements | query | - |
get_astronomy_data | Astronomy and solar/lunar data | query , date | - |
search_locations | Search and find locations (no weather data) | query | - |
get_timezone | Timezone information | query | - |
get_weather_for_sport_event | Sports event weather | query | - |
Note:
get_weather_history
is available but requires a premium WeatherAPI subscription.
๐ ๏ธ Requirements
- Python 3.11+
- uv package manager
- WeatherAPI API key (free tier available)
๐ Installation
Manual Installation
-
Clone the repository:
git clone https://github.com/yourusername/weather-api-mcp-server.git cd weather-api-mcp-server
-
Install dependencies with uv:
uv sync
-
Set up your API key:
# Create .env file echo "WEATHER_API_KEY=your_api_key_here" > .env
-
Get your WeatherAPI key:
- Sign up at WeatherAPI.com
- Copy your API key to the
.env
file
๐ Usage
Running the Server
Option 1 (recommended): Run via uvx console script
Add to your MCP client's settings (example for Claude Desktop):
{
"mcpServers": {
"weatherAPI": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/OriShmila/weather-api-mcp-server",
"weather-api-mcp-server"
],
"env": {
"WEATHER_API_KEY": "your_api_key_here"
}
}
}
}
Option 2: Local run (repo checkout)
# Start the MCP server from a local checkout
uv run python main.py
The server runs as an MCP server using stdin/stdout communication protocol.
Testing the Server
# Run comprehensive test suite (45+ tests)
uv run python test_server.py
Expected output:
๐ค๏ธ Weather API MCP Server Test Suite
==================================================
โ
Loaded 9 tool schemas
โ
Mapped 9 tool functions
๐ Validating schema structure...
โ
All schemas have valid structure
โ
All schemas have corresponding functions
โ
Loaded 5 schema definitions for $ref resolution
๐งช Running Tool Tests with Schema Validation
--------------------------------------------------
๐ Running 45 test cases with full schema validation...
...
==================================================
๐งช TEST SUMMARY
==================================================
Total Tests: 45
โ
Passed: 45
โ Failed: 0
๐ Success Rate: 100.0%
๐ง Configuration
Environment Variables
Variable | Description | Required |
---|---|---|
WEATHER_API_KEY | Your WeatherAPI.com API key | Yes |
Tool Schemas
All tool schemas are defined in tools.json
with:
- Input validation - Parameter types, constraints, patterns
- Output validation - Response structure and data types
- $ref definitions - Reusable schema components
- Error handling - Comprehensive validation rules
๐ Schema Validation
This server features comprehensive JSON Schema validation:
Input Validation
- โ Parameter types (string, integer, boolean)
- โ Required fields validation
- โ Pattern matching (date formats, etc.)
- โ Range constraints (min/max values)
- โ Enum validation
Output Validation
- โ Response structure validation
- โ Field type checking
- โ Required properties validation
- โ $ref resolution for reusable definitions
- โ Nested object validation
Example: Date Validation
# โ
Valid date format
"date": "2024-12-25"
# โ Invalid date format (caught by schema)
"date": "2024/12/25" # Error: does not match '^\\d{4}-\\d{2}-\\d{2}$'
๐งช Testing
The server includes comprehensive testing:
- 45 test cases covering all tools
- 5 tests per tool with different scenarios
- Error case validation for edge cases
- Real API call testing with live validation
- Schema validation testing for inputs/outputs
- Performance monitoring with response times
Test Categories
- Positive Tests - Valid inputs and expected outputs
- Negative Tests - Invalid inputs and error handling
- Edge Cases - Boundary conditions and limits
- Schema Tests - Input/output validation
- Performance Tests - Response time monitoring
๐ MCP Client Integration
Claude Desktop Configuration
Add to your Claude Desktop MCP settings:
{
"mcpServers": {
"weatherAPI": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/OriShmila/weather-api-mcp-server",
"weather-api-mcp-server"
],
"env": {
"WEATHER_API_KEY": "your_api_key_here"
}
}
}
}
Other MCP Clients
The server implements the standard MCP protocol and works with any MCP-compatible client:
- stdin/stdout communication
- JSON-RPC 2.0 protocol
- Tool listing and execution
- Comprehensive error handling
๐ Project Structure
weather-api-mcp-server/
โโโ main.py # MCP server implementation
โโโ tools.json # Tool schemas and definitions
โโโ test_server.py # Comprehensive test suite
โโโ test_cases.json # Test cases (45+ scenarios)
โโโ pyproject.toml # Project dependencies
โโโ .env # Environment variables
โโโ README.md # This file
๐ฏ Query Examples
Location Flexibility
# City names
"query": "London"
"query": "New York"
# Coordinates
"query": "40.7128,-74.0060"
# Postal codes
"query": "10001"
# Airport codes
"query": "LAX"
Weather Forecasts
# Basic forecast
{
"query": "Paris",
"days": 3
}
# Advanced forecast with air quality and alerts
{
"query": "Miami",
"days": 7,
"include_air_quality": true,
"include_alerts": true
}
๐ค Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
uv run python test_server.py
- Submit a pull request
๐ Acknowledgments
- WeatherAPI.com for providing comprehensive weather data
- MCP Framework for the protocol specification
- UV Package Manager for fast dependency management