MCP Weather Server

August 16, 2025 ยท View on GitHub

A Model Context Protocol (MCP) server that provides real-time weather alerts and forecasts for locations across the United States. Built with FastMCP and powered by the National Weather Service (NWS) API.

Author

Matheus Remigio
Contact: matheus.remido@gmail.com

๐ŸŒŸ Features

  • Weather Alerts: Get current weather alerts for any US state
  • Weather Forecasts: Retrieve detailed 5-day weather forecasts for specific coordinates
  • Real-time Data: Powered by the official National Weather Service API
  • MCP Integration: Seamlessly integrates with MCP-compatible clients and AI assistants
  • Async Support: Built with async/await for optimal performance
  • Error Handling: Robust error handling with graceful fallbacks

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.13 or higher
  • uv package manager (recommended)
  • MCP-compatible client (like Cursor IDE)

Installation

  1. Clone the repository

    git clone https://github.com/msremigio/mcp-server-weather.git
    cd mcp_weather
    
  2. Install dependencies using uv

    uv sync
    
  3. Activate the virtual environment

    uv shell
    

Running the Server

uv run weather.py

The server will start and listen for MCP protocol messages via stdio transport.

๐Ÿ”ง Configuration

MCP Client Configuration

Add the following to your MCP client configuration (e.g., mcp.json):

{
  "mcpServers": {
    "mcp_weather": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/your/mcp_weather/project",
        "run",
        "weather.py"
      ]
    }
  }
}

Note: Update the --directory path to match your actual project location.

๐Ÿ“š API Reference

Available Tools

1. Get Weather Alerts (get_alerts)

Retrieves current weather alerts for a specific US state.

Parameters:

  • state (str): Two-letter state abbreviation (e.g., "CA", "NY", "TX")

Returns:

  • Formatted string containing all active alerts for the specified state

Example Response:

Event: Severe Thunderstorm Warning
Area: Northern California
Severity: Severe
Description: Severe thunderstorms capable of producing large hail and damaging winds
Instructions: Move to an interior room on the lowest floor of a building

---

Event: Flash Flood Watch
Area: Southern California
Severity: Moderate
Description: Heavy rainfall may cause flash flooding
Instructions: Monitor weather conditions and be prepared to take action

2. Get Weather Forecast (get_forecast)

Retrieves a 5-day weather forecast for specific coordinates.

Parameters:

  • latitude (str): Latitude coordinate (decimal degrees)
  • longitude (str): Longitude coordinate (decimal degrees)

Returns:

  • Formatted string containing the next 5 forecast periods

Example Response:

Tonight:
- Temperature: 45ยฐF
- Wind: 5 mph NW
- Forecast: Clear skies with light winds

---

Tomorrow:
- Temperature: 72ยฐF
- Wind: 10 mph SW
- Forecast: Sunny and warm with increasing clouds in the afternoon

๐Ÿ—๏ธ Project Structure

mcp_weather/
โ”œโ”€โ”€ weather.py          # Main MCP server implementation
โ”œโ”€โ”€ main.py             # Simple entry point (placeholder)
โ”œโ”€โ”€ pyproject.toml      # Project configuration and dependencies
โ”œโ”€โ”€ mcp.json           # MCP client configuration template
โ”œโ”€โ”€ README.md          # This file
โ”œโ”€โ”€ uv.lock            # Dependency lock file
โ”œโ”€โ”€ .python-version    # Python version specification
โ””โ”€โ”€ .venv/             # Virtual environment directory

๐Ÿ”Œ Dependencies

  • httpx: Modern async HTTP client for API requests
  • mcp: Model Context Protocol implementation
  • FastMCP: FastMCP framework for building MCP servers

๐ŸŒ Data Source

This project uses the National Weather Service (NWS) API, which provides:

  • Real-time weather alerts and warnings
  • Detailed weather forecasts
  • Geographic point data
  • Free and reliable weather information

๐Ÿ› ๏ธ Development

Adding New Tools

To add new weather-related tools:

  1. Create a new async function in weather.py
  2. Decorate it with @mcp.tool()
  3. Add proper type hints and docstrings
  4. Implement the tool logic using the existing helper functions

Testing

# Run the server in development mode
uv run weather.py

# Test with MCP client tools
# The server will respond to MCP protocol messages

๐Ÿ“ Error Handling

The server includes comprehensive error handling:

  • HTTP request failures
  • API response validation
  • Network timeouts (30-second limit)
  • Graceful fallbacks for missing data

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

MIT License.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

For issues, questions, or contributions:

  • Open an issue on GitHub
  • Check the MCP documentation
  • Review the National Weather Service API documentation

Note: This server requires an active internet connection to fetch weather data from the NWS API.