Skip to main content

Weather MCP

MCP server that predicts rain for the next 7 days in any city and explains the prediction using SHAP values. Mirrors Part 3 of weather_shap.ipynb: XGBoost + SHAP TreeExplainer + live Open-Meteo data.

Tools

Tool Purpose
predict_rain_7day 7-day rain probability forecast for a city. Trains an XGBoost model on 2 years of historical data on first call, then caches it.
explain_rain_prediction SHAP factors for a specific forecasted day — which feature pushed the probability up or down and by how much.
city_model_info Metadata about the cached model (accuracy, training window).

Data source: Open-Meteo (no API key required).

Install

cd weather-mcp
python -m venv .venv
source .venv/bin/activate
pip install -e .

This installs the weather-mcp console script, which is what the MCP clients below will launch.

Running locally (smoke test)

weather-mcp

The server speaks MCP over stdio — it will sit waiting for JSON-RPC. Use Ctrl-C to stop. Real testing happens through one of the clients below.

Connect to Claude Desktop

Edit ~/.config/Claude/claude_desktop_config.json (Linux) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "weather": {
      "command": "/absolute/path/to/weather-mcp/.venv/bin/weather-mcp"
    }
  }
}

Restart Claude Desktop. You should see a 🔌 icon listing predict_rain_7day, explain_rain_prediction, and city_model_info.

Connect to Cursor

Settings → MCP → Add new MCP server:

  • Name: weather
  • Command: /absolute/path/to/weather-mcp/.venv/bin/weather-mcp

Connect to VS Code (Continue extension or any MCP-aware client)

Add to your client's MCP config:

{
  "mcpServers": {
    "weather": {
      "command": "/absolute/path/to/weather-mcp/.venv/bin/weather-mcp",
      "args": []
    }
  }
}

Example conversation

You: Will it rain in Tokyo over the next 7 days?

(client calls predict_rain_7day(city="Tokyo"))

Claude: Tomorrow shows a 78% chance of rain, day 3 drops to 12%, …

You: Why is day 1 so high?

(client calls explain_rain_prediction(city="Tokyo", day_index=0))

Claude: The biggest driver is forecasted precipitation = 8.4 mm (+1.92 log-odds), reinforced by a higher-than-usual min temperature …

How it works

  1. Geocode the city via Open-Meteo's geocoding endpoint.
  2. Train an XGBoost binary classifier on ~2 years of daily archive data (precipitation, temp_max, temp_min, windspeed → did it rain that day, derived from WMO weather codes). The trained model is cached per location.
  3. Predict by fetching the live forecast and running predict_proba.
  4. Explain with shap.TreeExplainer — exact Shapley values for the trained model, surfaced as ranked factors per day.

Notes

  • Models are cached in-process; restarting the server retrains on next call.
  • A given location key rounds lat/lon to two decimals, so "Tokyo" and a query near Tokyo Tower share the same model.
  • explain_rain_prediction will auto-run a 7-day prediction if you ask it before predict_rain_7day for that city.

Metadata

Release files for weather-shap-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for weather-shap-mcp 0.1.0
File Size Uploaded
weather_shap_mcp-0.1.0.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for weather-shap-mcp 0.1.0
File Interpreter ABI Platform
weather_shap_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.1 kB

Release files / weather_shap_mcp-0.1.0.tar.gz

Download URL weather_shap_mcp-0.1.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d0bc808111162d95ba2eb9a4a184e191a89360f72f6ab5d4551bb6214cbfe95c
BLAKE2b-256 checksum
How to use checksums
347c6d1bc7988ba2d1bdd6b3c7bb569be657592694442e6970b90359582204e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / weather_shap_mcp-0.1.0-py3-none-any.whl

Download URL weather_shap_mcp-0.1.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
983fc19e72c8a5bbadd93bbb35a8ad1ddc6e9cf09fe0d255c72f3af35f3cc63f
BLAKE2b-256 checksum
How to use checksums
fadab08f418705dcd1f27d5b9122961b9ba6af9d45ecd6f661aec97765f71ac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page