使用说明
MCP云服务器
使用FastMCP构建的模型上下文协议(MCP)服务器,通过服务器发送事件(SSE)公开全面的天气工具、资源和提示。专为在Google Cloud Run上部署而设计。
特性
- 美国天气(NWS):警报、预报、每小时预报、当前状况、雷达站、飓风跟踪
- 全球天气(Open Meteo):全球天气预报、空气质量、紫外线指数、海洋条件
- 地理编码(提名):将地址转换为坐标,反之亦然
- 公用事业:日出/日落时间、天气比较、综合总结
- MCP资源:天气词汇表、气象站列表、国家警报摘要
- MCP提示:旅行天气、恶劣天气分析、服装建议、户外活动适合性
- 苏格兰和南方能源公司运输:使用服务器发送的事件进行实时MCP通信
- 云运行就绪:已配置为Google Cloud Run部署
快速开始
地方发展
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run server
python server.py
服务器启动于 http://localhost:8080 默认情况下。设置 PORT 环境变量来改变它。
Docker部署
# Build image
docker build -t mcp-cloud-server .
# Run container
docker run -p 8080:8080 mcp-cloud-server
谷歌云运行部署
使用部署脚本(推荐):
# Basic deployment
python gcp_deploy.py --project-id <PROJECT_ID>
# Custom region and service name
python gcp_deploy.py -p <PROJECT_ID> -r europe-west1 -s weather-mcp
# Redeploy without rebuilding
python gcp_deploy.py -p <PROJECT_ID> --skip-build
或者手动使用gcloud:
# Build and push to Google Container Registry
gcloud builds submit --tag gcr.io/<PROJECT_ID>/mcp-server
# Deploy to Cloud Run
gcloud run deploy mcp-server \
--image gcr.io/<PROJECT_ID>/mcp-server \
--platform managed \
--region <REGION> \
--allow-unauthenticated
替换 <PROJECT_ID> 使用您的GCP项目ID和 <REGION> 与您的首选地区(例如。, us-central1).
MCP检验员测试
# Test local server
npx @modelcontextprotocol/inspector \
npx -y @modelcontextprotocol/server-sse-client \
--url http://localhost:8080/sse
# Test deployed server
npx @modelcontextprotocol/inspector \
npx -y @modelcontextprotocol/server-sse-client \
--url https://<SERVICE_URL>/sse
替换 <SERVICE_URL> 使用您的Cloud Run服务URL(例如。, mcp-server-xxxxx.us-central1.run.app).
MCP工具
美国天气(NWS API)
| 工具 | 说明 |
|---|---|
get_alerts |
获取美国某个州的天气警报 |
get_forecast |
获取美国位置的多日预报 |
get_hourly_forecast |
获取每小时预测(未来24小时) |
get_current_conditions |
从最近的车站获取当前状况 |
get_radar_stations |
列出附近的雷达站 |
get_active_hurricanes |
获得活跃的热带风暴/飓风 |
全球天气(Open Meteo)
| 工具 | 说明 |
|---|---|
get_global_forecast |
全球7天天气预报 |
get_global_hourly |
每小时预测(全球) |
get_air_quality |
空气质量指数和污染物 |
get_uv_index |
紫外线指数现状及预测 |
get_marine_forecast |
波高、方向、周期 |
地理编码(提名)
| 工具 | 说明 |
|---|---|
geocode_location |
将地名/地址转换为坐标 |
reverse_geocode |
将坐标转换为地址 |
公用事业
| 工具 | 说明 |
|---|---|
get_sunrise_sunset |
任何日期的日出/日落时间 |
compare_weather |
比较两个地点的天气 |
get_weather_summary |
综合天气概述 |
MCP资源
| 资源URI | 描述 |
|---|---|
weather://glossary |
天气术语定义 |
weather://stations/{state} |
列出美国各州的气象站 |
weather://alerts/national |
美国所有活动警报摘要 |
MCP提示
| 提示 | 描述 |
|---|---|
travel_weather |
两地之间的旅行天气简报 |
severe_weather_summary |
美国一州的恶劣天气分析 |
clothing_recommendation |
根据天气穿什么 |
outdoor_activity |
天气适合活动吗? |
客户端集成
Claude桌面应用程序
添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"weather": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sse-client",
"--url",
"https://<SERVICE_URL>/sse"
]
}
}
}
替换 <SERVICE_URL> 使用您的Cloud Run服务URL,然后重新启动Claude Desktop。
开发包
pip install mcp
import asyncio
from mcp.client.sse import sse_client
from mcp.client.session import ClientSession
SERVER_URL = "https://<SERVICE_URL>/sse"
async def main():
async with sse_client(SERVER_URL) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# List available tools
tools = await session.list_tools()
for tool in tools.tools:
print(f"- {tool.name}: {tool.description}")
# Call a tool
result = await session.call_tool("get_global_forecast", {
"latitude": 28.6139,
"longitude": 77.2090
})
print(result.content[0].text)
asyncio.run(main())
Types/Node.js SDK
npm install @modelcontextprotocol/sdk
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
const client = new Client({ name: "weather-client", version: "1.0.0" });
const transport = new SSEClientTransport(
new URL("https://<SERVICE_URL>/sse")
);
await client.connect(transport);
// List tools
const tools = await client.listTools();
// Call a tool
const result = await client.callTool("geocode_location", {
query: "Tokyo, Japan"
});
使用的API
所有API都是免费的,不需要API密钥:
- 美国国家气象局API -美国天气数据
- 开放天气 -全球天气、空气质量、海洋数据
- 提名 -地理编码(OpenStreetMap)
- Sunrise-Sunset.org -日出/日落时间
许可证
专有-Datavtar保留所有权利