weather-mcp
by peican996
README.md
# Weather MCP Server + MCP Log Proxy
两个 MCP (Model Context Protocol) 工具,通过 stdio 协议与 MCP 客户端(如 Claude Code、Cline、VS Code 等)交互。
```
weather-mcp/
├── weather.py # Weather MCP 服务器 — 查美国天气
├── main.py # 占位入口
├── pyproject.toml # 项目依赖
├── README.md
└── mcpLog/
├── mcp_log.py # MCP Log Proxy — 透明代理记录请求/响应
└── pyproject.toml # proxy 依赖
```
---
## 1. Weather MCP Server
提供两个工具,数据来源 [weather.gov](https://weather.gov) API。
### 安装
```bash
# 安装 uv(如果还没有)
pip install uv
# 同步依赖
uv sync
```
### 工具
| 工具 | 参数 | 说明 |
|---|---|---|
| `get_alerts` | `state: string` | 查询美国州的天气警报(两字母州代码,如 CA) |
| `get_forecast` | `latitude: float`, `longitude: float` | 查询经纬度处的天气预报 |
### 运行
```bash
uv run weather.py
```
---
## 2. MCP Log Proxy
透明 stdio 代理,记录 MCP 客户端与目标服务器之间的所有 JSON-RPC 流量。
```
Client ≤stdin/stdout≥ mcp_log.py ≤stdio≥ Target Server
│
logs/<timestamp>_<pid>.jsonl
```
### 安装
```bash
cd mcpLog
uv sync
```
### 命令行用法
```bash
python mcp_log.py <target_command> [target_args...] [--log-dir <dir>]
```
**示例** — 代理 weather 服务器:
```bash
python mcp_log.py python ../weather.py --log-dir ./logs
```
### 日志格式
每行一个 JSON 对象,字段:
| 字段 | 说明 |
|---|---|
| `ts` | UTC 时间戳 |
| `dir` | `META`(元信息)/ `REQUEST >>`(请求)/ `RESPONSE <<`(响应) |
| `msg` | 完整的 JSON-RPC 消息体 |
示例:
```json
{"ts":"2026-06-13T15:17:31","dir":"REQUEST >>","msg":{"method":"tools/call","params":{"name":"get_alerts","arguments":{"state":"CA"}},"jsonrpc":"2.0","id":5}}
{"ts":"2026-06-13T15:17:38","dir":"RESPONSE <<","msg":{"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"..."}]}}}
```
---
## 3. 配置 Cline(VS Code 插件)
编辑 `%APPDATA%/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`:
### 直连 weather(不打日志)
```json
{
"mcpServers": {
"weather": {
"autoApprove": ["get_forecast", "get_alerts"],
"disabled": false,
"timeout": 60,
"type": "stdio",
"command": "uv",
"args": [
"--directory",
"C:\\code\\python\\weather",
"run",
"weather.py"
]
}
}
}
```
### 通过 proxy 连接(记录所有请求日志)
```json
{
"mcpServers": {
"weather": {
"autoApprove": ["get_forecast", "get_alerts"],
"disabled": false,
"timeout": 60,
"type": "stdio",
"command": "C:\\code\\python\\weather\\mcpLog\\.venv\\Scripts\\python.exe",
"args": [
"C:\\code\\python\\weather\\mcpLog\\mcp_log.py",
"C:\\code\\python\\weather\\.venv\\Scripts\\python.exe",
"C:\\code\\python\\weather\\weather.py",
"--log-dir",
"C:\\code\\python\\weather\\mcpLog\\logs"
]
}
}
}
```
> **注意**:路径里的 `.venv\Scripts\python.exe` 是 Windows 的 venv 路径,macOS/Linux 改为 `.venv/bin/python`。
配置后 **reload Cline**(或重启 VS Code)即可生效,日志输出到 `mcpLog/logs/` 目录。
---
## 4. 配置 Claude Code
在项目根目录创建 `.mcp.json`:
```json
{
"mcpServers": {
"weather": {
"type": "stdio",
"command": "python",
"args": [
"mcpLog/mcp_log.py",
"python",
"weather.py",
"--log-dir",
"mcpLog/logs"
]
}
}
}
```
---
## 依赖
- Python ≥ 3.13
- [MCP SDK](https://github.com/modelcontextprotocol/python-sdk) ≥ 1.27
- httpx
- anyio
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues