weather-api-mcp-server

OriShmila/weather-api-mcp-server

3.2

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.

Tools
8
Resources
0
Prompts
0

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

ToolDescriptionRequired ParametersOptional Parameters
get_current_weatherCurrent weather conditionsqueryinclude_air_quality
get_weather_forecastWeather forecasts (1-14 days)querydays, include_air_quality, include_alerts
get_weather_alertsWeather warnings and alertsquery-
get_weather_airqualityAir quality measurementsquery-
get_astronomy_dataAstronomy and solar/lunar dataquery, date-
search_locationsSearch and find locations (no weather data)query-
get_timezoneTimezone informationquery-
get_weather_for_sport_eventSports event weatherquery-

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

  1. Clone the repository:

    git clone https://github.com/yourusername/weather-api-mcp-server.git
    cd weather-api-mcp-server
    
  2. Install dependencies with uv:

    uv sync
    
  3. Set up your API key:

    # Create .env file
    echo "WEATHER_API_KEY=your_api_key_here" > .env
    
  4. Get your WeatherAPI key:

๐Ÿ“– 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

VariableDescriptionRequired
WEATHER_API_KEYYour WeatherAPI.com API keyYes

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

  1. Positive Tests - Valid inputs and expected outputs
  2. Negative Tests - Invalid inputs and error handling
  3. Edge Cases - Boundary conditions and limits
  4. Schema Tests - Input/output validation
  5. 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

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass: uv run python test_server.py
  5. Submit a pull request

๐Ÿ™ Acknowledgments