Skip to main content
Glama
killerfirst

weather-china-mcp

by killerfirst
README.md
# 🌀 Weather China MCP Server

<p align="center">
  <a href="README.zh.md">πŸ‡¨πŸ‡³ δΈ­ζ–‡</a> &nbsp;|&nbsp; <b>πŸ‡ΊπŸ‡Έ English</b>
</p>

A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that provides real-time weather and 3-day forecast for Chinese cities, powered by [QWeather (ε’Œι£Žε€©ζ°”)](https://www.qweather.com) API.

> **Inspiration**: This project is a learning exercise by the author, inspired by the [MCP server weather tutorial](https://modelcontextprotocol.io) on modelcontextprotocol.io β€” which demonstrated building a US weather MCP server. This is the Chinese weather counterpart, adapted for the QWeather API.

---

## ✨ Features

- **Real-time weather** β€” temperature, feels-like, humidity, wind, visibility, and more
- **3-day forecast** β€” daily high/low, day/night weather, humidity, wind
- **MCP-native** β€” works with any MCP-compatible client (Claude Code, Codex, OpenClaw, etc.)
- **Secure** β€” API credentials stored in `.env`, never committed to Git

## πŸ“‹ Prerequisites

| Requirement | Description |
|-------------|-------------|
| **Python** | β‰₯ 3.11 |
| **uv** | Python package manager ([install](https://docs.astral.sh/uv/getting-started/installation/)) |
| **QWeather Account** | Free tier: 1,000 calls/day. Register at [console.qweather.com](https://console.qweather.com) |

After registering on QWeather Console:

1. Create a project β†’ get your **API Key**
2. Go to Settings β†’ copy your **dedicated API Host** (format: `xxx.xxx.qweatherapi.com`)

## πŸš€ Quick Start

```bash
# 1. Clone the repo
git clone <your-repo-url>
cd weather-china

# 2. Set up environment variables
cp .env.example .env
# Edit .env and fill in your QWeather API Key & API Host

# 3. Install dependencies
uv sync

# 4. Run the server (for testing)
uv run weather.py
```

## πŸ”§ MCP Client Configuration

### Claude Code

Add to `.mcp.json` in your project root (or `~/.claude/mcp.json` for global):

```json
{
  "mcpServers": {
    "weather-china": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/weather-china",
        "run",
        "weather.py"
      ]
    }
  }
}
```

Restart Claude Code or run `/mcp reload` to pick up the change.

### Codex (OpenAI)

In Codex, open Settings β†’ MCP Servers β†’ Add:

```json
{
  "mcpServers": {
    "weather-china": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/weather-china",
        "run",
        "weather.py"
      ]
    }
  }
}
```

### OpenClaw

Add to your OpenClaw MCP configuration file:

```yaml
mcp_servers:
  weather-china:
    command: uv
    args:
      - --directory
      - /path/to/weather-china
      - run
      - weather.py
```

### Other MCP Clients (Generic stdio)

Any MCP client that supports stdio transport:

```json
{
  "mcpServers": {
    "weather-china": {
      "command": "uv",
      "args": ["--directory", "/path/to/weather-china", "run", "weather.py"],
      "env": {
        "QWEATHER_API_KEY": "<your-api-key>",
        "QWEATHER_API_HOST": "<your-api-host>"
      }
    }
  }
}
```

> **Note**: If your client doesn't inherit shell environment variables, pass `QWEATHER_API_KEY` and `QWEATHER_API_HOST` via the `env` field as shown above. When using `.env` file, the server loads them automatically.

## πŸ›  Available Tools

### `get_weather`

Get real-time weather for a Chinese city.

```
Parameters:
  city: string β€” City name (e.g., "εŒ—δΊ¬", "上桷", "广州")
```

### `get_forecast`

Get 3-day weather forecast for a Chinese city.

```
Parameters:
  city: string β€” City name (e.g., "εŒ—δΊ¬", "上桷", "广州")
```

## πŸ“ Project Structure

```
weather-china/
β”œβ”€β”€ weather.py          # MCP server β€” main entry point
β”œβ”€β”€ main.py             # Placeholder entry
β”œβ”€β”€ .env.example        # Environment variable template
β”œβ”€β”€ .env                # Your credentials (gitignored)
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .mcp.json           # Claude Code MCP config (example)
β”œβ”€β”€ pyproject.toml      # Python project metadata & dependencies
β”œβ”€β”€ uv.lock             # Dependency lock file
β”œβ”€β”€ README.md           # English readme
└── README.zh.md        # Chinese readme
```

## πŸ”’ Security

- `.env` is listed in `.gitignore` β€” never commit your API credentials
- `.env.example` provides a template for others to set up their own credentials
- Both `QWEATHER_API_KEY` and `QWEATHER_API_HOST` are read from environment variables, not hardcoded

## πŸ“„ License

MIT

TDQS

A3.7/5.0

Scored across 2 tools

Disambiguation5/5

The two tools are clearly distinct: one provides real-time current weather, the other provides a 3-day forecast. There is no overlap or ambiguity in their purposes.

Naming Consistency5/5

Both tools follow the exact same verb_noun pattern (get_weather, get_forecast), using consistent snake_case and a clear 'get_' prefix.

Tool Count3/5

With only 2 tools, the server feels thin for a weather service, but it is functional for basic real-time and forecast queries. This falls on the borderline low end.

Completeness3/5

The core weather operations (current conditions and forecast) are covered, but gaps exist for additional useful features like air quality, historical data, or location suggestions, which agents might expect from a comprehensive weather server.

Maintenance

ActivityInactive
ResponsivenessNo issues