weather-mcp-server

shaynemeyer/weather-mcp-server

3.2

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 dayong@mcphub.com.

The Weather MCP Server provides real-time weather information for cities worldwide using the Open-Meteo API, integrating seamlessly with MCP-enabled applications.

Tools
1
Resources
0
Prompts
0

Weather MCP Server

A Model Context Protocol (MCP) server that provides real-time weather information for any city worldwide using the Open-Meteo API.

Features

  • Real-time weather data - Get current weather conditions for any city
  • Global coverage - Support for cities worldwide via geocoding
  • MCP compliant - Integrates seamlessly with MCP-enabled applications
  • Accurate location - Uses Open-Meteo's geocoding API for precise city identification
  • Comprehensive data - Temperature, precipitation, wind speed, cloud cover, and more

Architecture

graph TD
    A[MCP Client] -->|Request: get-weather| B[Weather MCP Server]
    B -->|City name| C[Open-Meteo Geocoding API]
    C -->|Coordinates| B
    B -->|Coordinates| D[Open-Meteo Weather API]
    D -->|Weather data| B
    B -->|Formatted response| A

    style A fill:#e1f5fe
    style B fill:#f3e5f5
    style C fill:#fff3e0
    style D fill:#fff3e0

Weather Data Flow

sequenceDiagram
    participant Client as MCP Client
    participant Server as Weather Server
    participant Geo as Geocoding API
    participant Weather as Weather API

    Client->>Server: get-weather("San Francisco")
    Server->>Geo: Search for "San Francisco"
    Geo-->>Server: Coordinates (37.7749, -122.4194)

    alt City found
        Server->>Weather: Get weather for coordinates
        Weather-->>Server: Current weather data
        Server-->>Client: Formatted weather response
    else City not found
        Server-->>Client: "City not found" error
    end

Installation

  1. Clone the repository

    git clone <repository-url>
    cd weather-mcp-server
    
  2. Install dependencies

    npm install
    
  3. Run the server

    node main.ts
    

Usage

The server provides a single tool called get-weather that accepts a city name and returns current weather conditions.

Tool: get-weather

Parameters:

  • city (string): Name of the city to get weather for

Example Request:

{
  "tool": "get-weather",
  "arguments": {
    "city": "London"
  }
}

Example Response:

{
  "content": [
    {
      "type": "text",
      "text": "{
        \"current\": {
          \"temperature_2m\": 68.5,
          \"apparent_temperature\": 70.2,
          \"is_day\": 1,
          \"precipitation\": 0.0,
          \"rain\": 0.0,
          \"weather_code\": 1,
          \"cloud_cover\": 25,
          \"wind_speed_10m\": 8.2
        }
      }"
    }
  ]
}

Configuration

The server uses the following APIs with default settings:

  • Geocoding API: https://geocoding-api.open-meteo.com/v1/search
  • Weather API: https://api.open-meteo.com/v1/forecast
  • Units: Fahrenheit, MPH, inches
  • Timezone: America/Los_Angeles (configurable in code)

Weather Data Fields

The weather response includes:

FieldDescriptionUnit
temperature_2mCurrent temperature�F
apparent_temperatureFeels-like temperature�F
is_dayDay/night indicator0/1
precipitationCurrent precipitationinches
rainRain amountinches
showersShower amountinches
weather_codeWeather condition code-
cloud_coverCloud coverage%
wind_speed_10mWind speed at 10mmph

Error Handling

The server handles common error scenarios:

  • City not found: Returns a user-friendly message when the geocoding API cannot locate the specified city
  • API errors: Network and API response errors are propagated appropriately
  • Invalid input: Input validation using Zod schemas

Dependencies

API Credits

This project uses the Open-Meteo API, which provides:

  • Free weather data with no API key required
  • High-quality meteorological data
  • Global coverage with 1km resolution
  • Historical and forecast data

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request