Skip to main content
Glama
Weather MCP Server

Weather MCP Server

by mailmirza
README.md
# Weather MCP Server

A small, beginner-friendly [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server built
with [FastMCP](https://gofastmcp.com) that lets an AI assistant look up current weather. It is meant as a
first server to read and modify: the common building blocks fit in about 100 lines.

**What it demonstrates**

- Tools with typed parameters and defaults: `get_weather(latitude, longitude, unit="celsius")`, plus
  two trivial ones, `add` and `get_word_count`
- Input validation and clear errors (bad coordinates, bad unit, upstream timeout)
- A resource (`config://server-info`) and a prompt (`weather_report`)
- Optional GitHub OAuth ([docs/auth.md](docs/auth.md)), and a shared bearer token pattern
- Running locally over stdio, or over the network over HTTP ([docs/deployment.md](docs/deployment.md))

Weather data comes from [Open-Meteo](https://open-meteo.com/), which needs no API key.

## Quick start

```bash
git clone https://github.com/mailmirza/weather-mcp-server.git
cd weather-mcp-server
python -m venv venv
source venv/bin/activate         # Windows PowerShell: .\venv\Scripts\Activate.ps1
pip install -r requirements.txt
python server.py                 # stdio mode: it waits for an MCP client
```

Test it with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector). Let the Inspector
launch the server, and do not type into the server's own terminal:

```bash
npx @modelcontextprotocol/inspector python server.py
```

## Use it from an MCP client

**Local (stdio).** For Claude Desktop, add this to `claude_desktop_config.json` (use full paths; on Windows
use `venv\\Scripts\\python.exe` with double backslashes):

```json
{
  "mcpServers": {
    "weather": {
      "command": "/full/path/to/venv/bin/python",
      "args": ["/full/path/to/weather-mcp-server/server.py"]
    }
  }
}
```

**Over the network (HTTP).** Run with `MCP_TRANSPORT=http`. Claude's custom connector dialog expects an
`https://` URL, so put the server behind a reverse proxy with a certificate. See
[docs/deployment.md](docs/deployment.md).

Example prompts once it is connected:

- "Use the weather connector's get_weather tool for latitude 25.2048, longitude 55.2708."
- "Same place, in fahrenheit."
- "Use the weather connector to compare the current temperature in Dubai and London."

Naming the connector matters: if your AI app has its own built-in weather feature, it may use that instead.

## Configuration

| Variable | Meaning |
|---|---|
| `MCP_TRANSPORT` | `stdio` (default) or `http` |
| `MCP_HOST` | Bind address for HTTP, default `127.0.0.1`. Use `0.0.0.0` only behind a proxy or firewall |
| `MCP_PORT` | HTTP port, default `8000` |
| `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, `MCP_BASE_URL` | Turn on GitHub OAuth, see [docs/auth.md](docs/auth.md) |

## Lessons learned

1. **stdio and `print()` do not mix.** In stdio mode stdout carries the protocol. Print to `sys.stderr`
   (or use `logging`), and never type into the terminal of a running stdio server.
2. **Docstrings are instructions.** FastMCP turns a tool's docstring and type hints into the schema the
   model reads. Say valid ranges and units there.
3. **The host may prefer its own tool.** Name the connector in your prompt.
4. **Client support varies.** When this was written (August 2026), Claude Desktop used the *tools* from a
   connector but did not surface its prompts or resources in chat. MCP Inspector shows all three.
5. **Auth options depend on the client.** A static bearer token works with Inspector, but Claude Desktop's
   connector dialog offered only OAuth client ID and secret fields. See [docs/auth.md](docs/auth.md).
6. **Windows notes.** The command is `python`, not `python3`. A new PATH needs a new terminal. If
   `Activate.ps1` is blocked, run `Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned`.

## Attribution

Weather data by [Open-Meteo.com](https://open-meteo.com/), licensed CC BY 4.0. Their free API is meant for
non-commercial use, so check their terms before building on it.

## License

[MIT](LICENSE)