
Deploying & Connecting Your Remote MCP Weather Server

2025.05.02
0
Python天气服务实时数据开发者工具位置服务
mcp-server-weather-example 是一个基于 Model Context Protocol (MCP) 的云服务,用于提供实时天气数据。它使用美国国家气象局 API,支持 Server-Sent Events (SSE) 进行实时通信,并通过 API 密钥进行安全认证。该项目适合需要实时天气数据的开发者,可以轻松部署到 Azure Container Apps,并与 Visual Studio Code 和 GitHub Copilot 集成。
View on GitHub
Overview
基本能力
产品定位
mcp-server-weather-example 是一个实时天气数据服务,专为开发者设计,用于获取和处理实时天气信息。
核心功能
- 实时天气数据:通过美国国家气象局 API 获取实时天气数据。
- Server-Sent Events (SSE):支持实时通信,确保数据及时更新。
- API 密钥认证:提供安全的 API 密钥认证机制。
- FastAPI 支持:基于 FastAPI 构建,提供高效的 API 服务。
- 云部署:支持部署到 Azure Container Apps,方便云端运行。
- Visual Studio Code 集成:可以与 VS Code 的 MCP 扩展无缝集成。
- GitHub Copilot 支持:支持通过 GitHub Copilot 进行交互式查询。
适用场景
- 开发者工具:为开发者提供实时天气数据,用于构建天气相关的应用程序。
- 实时监控:用于监控特定地区的天气变化,如警报和预报。
- 集成开发环境:在 VS Code 中直接查询天气数据,提升开发效率。
- 自动化代理:通过 GitHub Copilot 自动获取天气信息,用于自动化任务。
工具列表
get_alerts()
:获取特定地区的天气警报。get_forecast()
:获取特定地区的天气预报。
常见问题解答
- 如何设置 API 密钥?
- 通过环境变量
API_KEYS
设置 API 密钥,支持多个密钥。 - 如何部署到 Azure?
- 使用 Azure CLI 命令
az containerapp up
进行部署。 - 如何与 VS Code 集成?
- 在
.vscode/mcp.json
中配置服务器信息,并通过 MCP 扩展连接。
使用教程
使用依赖
-
克隆仓库:
bash git clone https://github.com/your-username/mcp-weather-server.git cd mcp-weather-server
-
设置 API 密钥:
bash export API_KEYS=<YOUR_API_KEY>
安装教程
- 使用 Azure CLI 部署:
bash az containerapp up \ -g <RESOURCE_GROUP> \ -n weather-mcp \ --environment <CONTAINERAPPS_ENV_NAME> \ -l westus \ --env-vars API_KEYS=<YOUR_API_KEY> \ --source .
调试方式
-
在 VS Code 中配置
.vscode/mcp.json
:json { "inputs": [ { "type": "promptString", "id": "weather-api-key", "description": "Weather API Key", "password": true } ], "servers": { "weather-sse": { "type": "sse", "url": "https://weather-mcp.orangebush.westus.azurecontainerapps.io/sse", "headers": { "x-api-key": "${input:weather-api-key}" } } } }
-
启动 MCP 扩展并输入 API 密钥。
- 通过 GitHub Copilot 查询天气数据。