MCP Weather Server

MCP Weather Server

MCP server that provides current weather and forecasts via Open-Meteo API, with an optional ML-based next-day max temperature prediction.

Category
访问服务器

README

MCP Weather Server

Minimal MCP server that exposes weather data via tools using the Open-Meteo API (no API key required).


Architecture

The project has three parts: a client (Cursor or the Python test client), the MCP server (this repo), and the Open-Meteo API. The client and server talk over stdio (stdin/stdout); the server talks to the API over HTTPS.

flowchart LR
  subgraph local [Your machine]
    Client[MCP Client]
    Server[MCP Server]
  end
  API[Open-Meteo API]
  Client <-->|"stdio (JSON-RPC)"| Server
  Server -->|"HTTPS GET"| API

How client and server communicate:

  1. The client starts the server as a subprocess and connects to it via stdio (standard input/output).
  2. Messages are JSON-RPC over stdio: the client sends requests (e.g. "list tools", "call tool X with args Y"); the server responds with results.
  3. When a tool is called, the server runs the tool logic (e.g. get_current_weather), which may call the Open-Meteo API; the server then sends the tool result back to the client over stdio.
sequenceDiagram
  participant Client as MCP Client
  participant Server as MCP Server
  participant API as Open-Meteo API

  Client->>Server: Initialize (stdio)
  Server-->>Client: Ready

  Client->>Server: ListTools
  Server-->>Client: get_current_weather, get_forecast

  Client->>Server: CallTool get_current_weather(5.98, 80.43)
  Server->>API: GET forecast?latitude=5.98&longitude=80.43
  API-->>Server: JSON weather data
  Server-->>Client: "Temperature: ...°C, Humidity: ...%..."

Summary:

Component Role
MCP Client Starts the server process, sends JSON-RPC over stdin, reads responses from stdout. Can be Cursor, the Python client.py, or MCP Inspector.
MCP Server Runs as a subprocess. Listens on stdin for requests, executes tools (calling weather.get_weather), returns results on stdout.
Open-Meteo API External HTTP API. The server calls it when a weather tool is invoked; the client never talks to it directly.

Setup

Windows (PowerShell):

python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt

Linux / WSL:

# If venv fails, install first: sudo apt install python3.10-venv
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

If you cannot create a venv (e.g. WSL without python3-venv), install into your user site-packages and use python3:

pip install --user -r requirements.txt

Run the server (for Cursor / other MCP hosts)

python server.py
# or on Linux/WSL: python3 server.py

The server uses stdio transport: it reads from stdin and writes to stdout. Cursor (or another MCP host) starts this process and talks to it over those streams.


How to use the Python client

The client (client.py) is a small script that connects to the MCP server via stdio and calls the weather tools. Use it to verify that the server works without Cursor.

Steps:

  1. From the project directory, with dependencies installed (see Setup):

    Windows:

    python client.py
    

    Linux / WSL:

    python3 client.py
    
  2. What the client does:

    • Starts server.py as a subprocess.
    • Connects to it over stdio (stdin/stdout).
    • Sends ListTools and prints the tool names.
    • Calls get_current_weather(5.98, 80.43) (Weligama, Sri Lanka) and prints the result.
    • Calls get_forecast(5.98, 80.43, days=3) (Weligama, 3 days) and prints the result.
  3. Example output (Weligama, Sri Lanka):

    Tools: ['get_current_weather', 'get_forecast']
    
    --- Weligama, Sri Lanka — current weather ---
    Temperature: 28.5°C, Humidity: 75%, Wind: 5.2 km/h, Weather code: 1
    
    --- Weligama, Sri Lanka — 3-day forecast ---
    Temperature: 28.5°C, Humidity: 75%, Wind: 5.2 km/h, Weather code: 1
    2026-02-08: max 29.1°C, min 25.2°C
    2026-02-09: max 29.5°C, min 25.8°C
    2026-02-10: max 29.2°C, min 25.5°C
    

You do not need to run server.py in another terminal; the client starts it automatically.


Cursor MCP config

Add the server to Cursor so the editor can call the weather tools (e.g. from chat).

Settings → MCP (or edit ~/.cursor/mcp.json):

{
  "mcpServers": {
    "weather": {
      "command": "python",
      "args": ["C:\\Users\\dolgo\\Desktop\\ai_projects\\mcp_server\\server.py"]
    }
  }
}

WSL: use python3 and the Linux path to server.py:

"command": "python3",
"args": ["/mnt/c/Users/dolgo/Desktop/ai_projects/mcp_server/server.py"]

Optional: use the venv Python so Cursor uses the same environment:

"command": "C:\\Users\\dolgo\\Desktop\\ai_projects\\mcp_server\\.venv\\Scripts\\python.exe",
"args": ["C:\\Users\\dolgo\\Desktop\\ai_projects\\mcp_server\\server.py"]

Tools

Tool Arguments Description
get_current_weather latitude, longitude Current temperature, humidity, wind speed, weather code.
get_forecast latitude, longitude, days (1–7) Current conditions plus daily min/max for the next days days.
get_model_forecast latitude, longitude Next-day max temperature from the trained ML model (requires training first).

Example: “What’s the weather in Weligama?” → use latitude 5.98, longitude 80.43 (Weligama, Sri Lanka).


ML predictive model (next-day max temperature)

A small Random Forest model predicts tomorrow's max temperature from today's daily weather (max/min temp, humidity, wind, day of year). It is trained on historical data from Open-Meteo and exposed as the get_model_forecast MCP tool.

One-time setup: fetch data and train

  1. Fetch historical daily weather (e.g. Weligama, 2022–today):

    python scripts/fetch_history.py
    # optional: --lat 5.98 --lon 80.43 --start 2022-01-01 --end 2025-02-06
    

    Output: data/weligama_history.csv.

  2. Train the model:

    python scripts/train.py
    # optional: --data data/weligama_history.csv --out model/model.joblib
    

    Output: model/model.joblib (and MAE in °C on a held-out set).

  3. Use the tool: After training, get_model_forecast(latitude, longitude) uses today's conditions (from the forecast API) and the trained model to return a predicted tomorrow max temperature.

Flow

  • Training: scripts/fetch_history.py → historical daily data → scripts/train.py → model/model.joblib.
  • Inference: MCP tool get_model_forecast calls the forecast API for today's daily values, builds the feature vector, runs the model, returns e.g. "Model predicts tomorrow's max temperature: 29.2°C".

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选