使用说明
气象MCP服务器+代理+Web用户界面
该项目已集成为一个堆栈:
FastMCP使用MCP工具的服务器,FastAPI后端+内置最小前端- CLI/daemon 代理
openai-agents, - SQLite中的默认存储(可选JSON后端)。
建筑
src/weather_mcp/client.py-外部Weather API的HTTP客户端。src/weather_mcp/tools.py--MCP工具(get_weather,schedule,run_scheduled_jobs,get_weather_summary和博士。).src/weather_mcp/scheduler_store.py--存储/调度程序(scheduled_jobs,weather_records)+JSON回退。src/weather_agent/web.py--FastAPI端点+UI仪表板。src/weather_agent/daemon.py-24/7 DAEMON,定期运行Due Jobs。src/weather_agent/service.py-为OpenAI Agent+MCP运行时聊天。
MCP工具
get_weather
输入:
city或latitude/longitudeunits(默认)metric)
行为:
- 通过外部API获取天气
- 使答案正常化,
- 将Snapshot保存到Storage中,
- 返回JSON:
{
"location": "Warsaw, Mazowieckie, Poland",
"temperature": 12.3,
"feels_like": 10.8,
"humidity": 81,
"wind_speed": 4.2,
"condition": "пасмурно",
"source": "open-meteo",
"collected_at": "2026-03-12T10:00:00+00:00",
"units": "metric"
}
schedule
输入:
target(get_weather)params(论据为get_weather)mode:once|interval|cronrun_at(为)once)every_seconds或every(为)interval)- 支持秒和分钟:
300,90s,5m,2 минуты
- 支持秒和分钟:
cron(为)cron)enabledtimezone
返回:
{
"job_id": "...",
"target": "get_weather",
"mode": "interval",
"next_run_at": "...",
"status": "scheduled"
}
run_scheduled_jobs
- 从存储中提取Due Jobs,
- 执行
get_weather, - 保存结果,
- 数
next_run_at, - 返回执行结果。
get_weather_summary
过滤器:
locationdate_fromdate_to
组件:
- 记录_计数
- 最低/最高/平均温度
- 平均湿度
- top_条件
- 观测周期
Web API+用户界面
启动:
uv run weather-web
打开: http://127.0.0.1:8008
UI包括:
- 手动呼叫
get_weather, - 创建Schedule,
- 启动Due Jobs,
- 浏览Jobs,
- 数据库清理(Jobs+Records)
- 查看Records,
- 地点/时期摘要。
UI注释:
- 时区以秒和分钟为单位(
300,90s,5m); - 将请求发送到聊天室后,并在对时间表进行操作后,列出当前活动列表
jobs自动更新。
可用的Endpoints:
POST /api/weatherPOST /api/schedulePOST /api/schedules/run-dueGET /api/schedulesGET /api/recordsGET /api/summaryPOST /api/storage/clearPOST /api/chatGET /healthz
24/7剧本
- 创建时间表(
schedule)通过UI或MCP。 - 启动daemon:
uv run weather-summary-daemon
- DAEMON循环调用
run_scheduled_jobs然后打印报告。
存储
默认SQLite:
scheduled_jobsweather_records
JSON Backend选项:
- 单一JSON文件(Jobs+Records)
配置(.env)
见E/CN.4/Sub.2/2000/SR.1。 .env.example关键变量:
OPENAI_API_KEYOPENAI_MODELWEATHER_API_KEYWEATHER_API_BASE_URLWEATHER_GEOCODING_URLWEATHER_STORAGE_BACKEND(sqlite/json)DATABASE_URLWEATHER_JSON_PATHSCHEDULER_TICK_SECONDSSCHEDULER_MAX_JOBSSUMMARY_DAEMON_POLL_SECONDSSUMMARY_DAEMON_MAX_JOBSAPP_TIMEZONE
局部起动
uv sync
cp .env.example .env
# заполнить OPENAI_API_KEY
uv run weather-mcp-server
# или
uv run weather-web
# или
uv run weather-agent
# или
uv run weather-summary-daemon
测试和镜头
uv run ruff check .
uv run pytest
