Content
# Python weather MCP server
An example [Model Context Protocol](https://modelcontextprotocol.io/) server
built with the official Python SDK. It uses Open-Meteo's geocoding and forecast
APIs, so no API key is required.
The server exposes two tools, both accepting an optional `location`:
- `get_current_weather` returns structured data and displays a responsive
weather card in ChatGPT.
- `get_current_weather_text` returns the same structured data without attaching
a widget, allowing ChatGPT to provide a conventional text response.
MCP clients can fill the location from a user's prompt (for example, “What is
the weather in Tokyo?”). When no place is supplied, the server uses the
configured default location.
## Install and run
Dependencies are already recorded in `pyproject.toml`:
```shell
uv sync
uv run main.py
```
The server uses Streamable HTTP at `http://127.0.0.1:8000/mcp`, which is the
transport required when connecting it to ChatGPT.
For interactive development with the MCP Inspector:
```shell
uv run mcp dev main.py
```
To change the fixed fallback location:
```powershell
$env:DEFAULT_WEATHER_LOCATION = "Maribor, Slovenia"
uv run main.py
```
## Connect from ChatGPT
ChatGPT must be able to reach the server through a public HTTPS URL. For local
development, use Cloudflare Tunnel to expose port 8000.
### Install Cloudflared
On Windows, install Cloudflared with WinGet:
```powershell
winget install --id Cloudflare.cloudflared
```
Open a new terminal after installation and verify that it is available:
```powershell
cloudflared --version
```
### Start the server and tunnel
In the first terminal, start the MCP server:
```shell
uv run main.py
```
In a second terminal, run the included tunnel script:
```powershell
.\scripts\make_tunnel.ps1
```
Cloudflared prints a temporary public URL similar to:
```text
https://example-name.trycloudflare.com
```
Keep both terminals running. Create a developer-mode app in ChatGPT using the
public URL with `/mcp` appended:
```text
https://example-name.trycloudflare.com/mcp
```
After changing the widget markup, reconnect or refresh the connector. The
versioned `ui://widget/weather-v1.html` URI prevents an older widget bundle from
being reused.
## Other MCP clients
Connect any Streamable HTTP-capable client to `http://127.0.0.1:8000/mcp`.
Example prompts:
- “Show the weather widget for Celje.” — uses `get_current_weather`.
- “Give me a text-only weather report for Reykjavík.” — uses
`get_current_weather_text`.
Weather data is provided by [Open-Meteo](https://open-meteo.com/).