Integrates with Google Gemini 2.5 Flash model through LangChain to provide natural language weather queries and intelligent date interpretation for weather data requests
Uses LangChain framework to create React Agent mode for natural language weather queries, enabling intelligent processing of time expressions like 'yesterday', 'tomorrow', and '3 days ago'
Weather MCP 🌤️
一個 Model Context Protocol (MCP) 天氣查詢應用專案,提供天氣數據檢索、LangChain Agent 整合和資料視覺化功能。
🚀 功能特色
核心功能
MCP 伺服器: 基於 FastMCP 的 stdio 協定天氣工具伺服器
MCP 客戶端: 支援異步操作和錯誤處理的客戶端工具
LangChain 整合: React Agent 模式,支援自然語言天氣查詢
資料視覺化: 使用 matplotlib 的天氣趨勢圖表
多語言支援: 中英文天氣查詢和回應
天氣工具
🌍 地理編碼: 城市名稱轉經緯度 (Open-Meteo Geocoding API)
🌡️ 天氣預報: 1-24小時逐時天氣預報 (Open-Meteo Forecast API)
📅 多日預報: 支援 1-16 天天氣預報,可指定日期查詢
🕒 歷史天氣: 支援查詢過去 92 天的天氣數據
🤖 智能日期: 自動判斷過去/未來,只需提供日期
🗣️ 自然語言: Agent 自動理解「昨天」「明天」「3天前」等時間表達
⚠️ 天氣警報: 天氣警報查詢 (示意功能)
📊 資料視覺化: 溫度、濕度、降水機率和風速圖表
📦 專案結構
🛠️ 安裝與設定
1. 複製專案
2. 建立虛擬環境
3. 安裝依賴
4. 設定環境變數 (Agent 功能需要)
注意: 程式會自動讀取 .env
檔案(需要 python-dotenv
套件,已包含在 requirements.txt 中)
🏃♂️ 快速開始
快速測試
基本使用
LangChain Agent 模式
資料視覺化
🎯 主程式使用
互動模式
互動模式支援以下命令:
viz [city] [date]
- 天氣視覺化(日期為可選的 YYYY-MM-DD 格式)raw [city] [date]
- 顯示原始天氣數據(日期為可選的 YYYY-MM-DD 格式)自然語言查詢(需要 API Key)
範例:
執行範例
使用範例程式
🔧 API 參考
WeatherMCPClient
WeatherAgent
WeatherVisualizer
🌐 支援的城市
內建中英文城市名稱對照:
日本/東京 → Tokyo
台灣/台北 → Taipei
中國/北京 → Beijing
韓國/首爾 → Seoul
美國/華盛頓 → Washington
英國/倫敦 → London
法國/巴黎 → Paris
德國/柏林 → Berlin
印度/新德里 → New Delhi
📊 資料來源
地理編碼: Open-Meteo Geocoding API
天氣預報: Open-Meteo Forecast API
AI 模型: Google Gemini 2.5 Flash (透過 LangChain)
🧪 測試
🤝 貢獻
Fork 專案
建立功能分支 (
git checkout -b feature/amazing-feature
)提交變更 (
git commit -m 'Add amazing feature'
)推送到分支 (
git push origin feature/amazing-feature
)開啟 Pull Request
📝 License
本專案採用 MIT License - 詳見 LICENSE 檔案。
🔍 故障排除
常見問題
MCP 伺服器啟動失敗
確認已安裝所有依賴套件
檢查
mcp_server.log
錯誤訊息
Agent 功能無法使用
確認已設定
GOOGLE_API_KEY
環境變數檢查 API Key 是否有效
視覺化圖表無法顯示
確認已安裝 matplotlib
在 Jupyter 環境中使用
%matplotlib inline
網路連線錯誤
檢查網路連線
確認防火牆設定允許存取 Open-Meteo API
Debug 模式
📚 進階功能
歷史與未來天氣查詢
支援查詢過去 92 天和未來 16 天的天氣,系統自動判斷:
自然語言查詢:Agent 自動理解時間表達
詳細說明請參考:
docs/DATE_FEATURE.md - viz/raw 日期功能說明
docs/HISTORICAL_WEATHER.md - 歷史天氣查詢
docs/MULTI_DAY_FORECAST.md - 多日預報功能
📞 支援與聯絡
問題回報: GitHub Issues
文件: 專案 Wiki
範例:
examples/
目錄
📖 更多文檔
HISTORICAL_WEATHER.md - 歷史天氣查詢功能
MULTI_DAY_FORECAST.md - 多日預報功能說明
LOGGING.md - 日誌系統說明
SERVER_STARTUP.md - 伺服器啟動機制
DYNAMIC_HOURS.md - 動態時間功能
ENV_SETUP.md - 環境變數設定
Weather MCP - 讓天氣查詢變得簡單而強大! 🌈
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables weather data retrieval and visualization with support for geocoding, multi-day forecasts, historical weather queries, and natural language processing through LangChain integration. Supports both current and historical weather data with interactive charts and multiple language support.