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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weather_shap_mcp-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weather_shap_mcp-0.1.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file weather_shap_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: weather_shap_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for weather_shap_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0bc808111162d95ba2eb9a4a184e191a89360f72f6ab5d4551bb6214cbfe95c
MD5 3d237227a8b3075b45d1e57a5509be5b
BLAKE2b-256 347c6d1bc7988ba2d1bdd6b3c7bb569be657592694442e6970b90359582204e5

See more details on using hashes here.

File details

Details for the file weather_shap_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for weather_shap_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 983fc19e72c8a5bbadd93bbb35a8ad1ddc6e9cf09fe0d255c72f3af35f3cc63f
MD5 f3e91cd824a491de10b3b594e0e7c3a4
BLAKE2b-256 fadab08f418705dcd1f27d5b9122961b9ba6af9d45ecd6f661aec97765f71ac4

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page