Manages environment variables including API keys for various services through the python-dotenv package.
Uses FastAPI to build the SSE (Server-Sent Events) server implementation, providing a web-based interface for the MCP weather service.
Provides integration with Google's Gemini AI model, allowing it to process queries and interact with weather services.
Uses Mermaid for architectural diagrams in the documentation, visualizing the system's components and interactions.
Connects to OpenAI's GPT models to handle user queries and interact with weather data through the MCP framework.
Built with Python 3.12+ as the core development language, leveraging modern Python features for the MCP implementation.
MCP Weather Sample
一個完整的 Model Context Protocol (MCP) 示範專案,展示如何整合天氣服務與多種 AI 模型。
專案簡介
MCP Weather Sample 是一個基於 MCP (Model Context Protocol) 的示範應用程式,展示如何建立一個完��的客戶端-伺服器架構,整合天氣 API 服務與多種 AI 模型 (Claude、GPT、Gemini)。專案支援兩種傳輸模式:STDIO 和 SSE (Server-Sent Events),提供靈活的部署選項。
核心功能
- 🌤️ 天氣查詢服務: 整合 NOAA Weather API,提供即時天氣預報和警報
- 🤖 多 AI 模型支援: 支援 Anthropic Claude、OpenAI GPT 和 Google Gemini 模型
- 🔄 雙傳輸模式: 支援 STDIO(本地)和 SSE(遠端)兩種連接方式
- 🔐 安全認證: 內建 API 金鑰驗證機制
- ⚡ 異步架構: 全面使用 Python asyncio 提供高效能處理
- 🛠️ 工具導向: 基於 MCP 工具呼叫模式的 AI 互動
技術亮點
- 現代 Python: 使用 Python 3.12+ 的最新特性
- FastAPI 整合: 使用 FastAPI 和 FastMCP 建構 SSE 伺服器
- 模組化設計: 清晰的客戶端和伺服器分離架構
- 配置驅動: 透過 JSON 配置文件管理多伺服器設定
技術堆疊
核心框架
- Python 3.12+: 主要開發語言
- MCP >=1.12.2: Model Context Protocol 核心框架
- FastAPI >=0.116.1: 現代 Web 框架(SSE 模式)
- FastMCP: 基於 FastAPI 的 MCP 伺服器實現
AI 模型整合
- Anthropic >=0.59.0: Claude AI 模型
- OpenAI >=1.97.1: GPT 模型
- Google GenAI >=1.27.0: Gemini 模型
網路與資料處理
- httpx >=0.28.1: 異步 HTTP 客戶端
- jsonschema >=4.25.0: JSON Schema 驗證
- python-dotenv >=1.1.1: 環境變數管理
快速開始
環境需求
- Python 3.12 或更高版本
- UV 套件管理器(建議)或 pip
- 有效的 API 金鑰:
- NOAA Weather API(免費)
- AI 模型 API 金鑰(Anthropic、OpenAI 或 Google)
安裝步驟
- 複製專案
- 安裝依賴
- 配置環境變數
- 設定伺服器配置檢查並修改
servers-config.json
檔案中的設定:註意:your_access_token
設定在 src/servers/weather/sse/user_db.py 中。
基本使用範例
1. 啟動 SSE 天氣伺服器
2. 啟動 MCP 客戶端
3. 基本天氣查詢
架構概覽
主要元件
MCP 客戶端 (src/client/client.py
)
- MCPClient: 單一 MCP 伺服器連接管理
- MCPHost: 多伺服器管理和 AI 模型整合
- ModelVendor: AI 模型供應商枚舉
天氣伺服器
- STDIO 模式 (
src/servers/weather/stdio/weather.py
): 本地標準輸入輸出連接 - SSE 模式 (
src/servers/weather/sse/mcp-weather.py
): HTTP SSE 遠端連接
提供的工具
get_alerts
: 獲取美國州份的天氣警報get_forecast
: 獲取指定座標的詳細天氣預報
進階功能
工具權限控制
透過 servers-config.json
精確控制每個伺服器可使用的工具:
API 金鑰管理
SSE 模式支援多種認證方式:
- HTTP Header:
x-api-key
- Bearer Token:
Authorization: Bearer <token>
- Query Parameter:
?api_key=<key>
文件導覽
授權條款
本專案採用 MIT 授權條款。
貢獻指南
歡迎參與專案貢獻!請參閱 貢獻指南 了解如何:
- 回報問題
- 提交功能請求
- 提供程式碼貢獻
- 改進文件
支援與回饋
如有問題或建議,請:
開始您的 MCP 之旅! 🚀 探索如何用 Model Context Protocol 建構智慧應用程式。
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A demonstration project for Model Context Protocol (MCP) that integrates weather services with multiple AI models (Claude, GPT, Gemini), enabling natural language queries for weather alerts and forecasts.
Related MCP Servers
- AsecurityFlicenseAqualityA Model Context Protocol server that provides real-time weather information and 5-day forecasts to AI assistants, supporting multiple languages and flexible units.Last updated -38TypeScript
- -securityFlicense-qualityA Model Context Protocol server that enables AI models to fetch weather alerts and detailed forecasts for US locations using the National Weather Service API.Last updated -71TypeScript
- -securityFlicense-qualityA Model Context Protocol (MCP) server that enables AI assistants and LLMs to access real-time weather data and forecasts by connecting to the OpenWeatherMap API.Last updated -Python
- -securityFlicense-qualityA modular server based on Model Context Protocol (MCP) that provides weather queries, mathematical calculations, and search functionalities.Last updated -TypeScript