Weather MCP Service
Used for API key management and configuration through environment variables loaded from .env files
Supports repository cloning for installation of the weather service
Hosts the weather-mcp repository which can be cloned for installation
Provides foundational components for building the weather information service
Powers the workflow for processing and responding to weather queries
Supported as a deployment platform with specific activation instructions
Core runtime environment (3.11+) required for the weather service
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Weather MCP Servicewhat's the forecast for New York City?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
天气信息与多源工具集成系统
这个项目展示了如何整合多种工具来源(自定义工具、本地MCP服务和第三方API)到一个统一的AI代理中,使用LangGraph框架和MCP协议,实现一个功能丰富的智能助手系统。
项目组件
1. 天气服务器 (weather.py)
提供天气相关API工具:
get_alerts: 获取美国州级天气警报get_forecast: 根据经纬度获取天气预报
基于MCP协议实现的本地服务,提供实时天气信息访问。
2. 自定义工具 (langgraph_tools.py)
提供一系列基础工具:
数学工具:加法、减法、乘法、除法、平方根、幂运算
字符串工具:字符串连接、转大写、转小写
这些工具使用LangChain的@tool装饰器定义,可以被AI代理调用。
3. 第三方MCP工具 (mcp_third_party.py)
集成第三方MCP服务:
智谱Web搜索工具:通过智谱AI提供的MCP接口获取实时Web搜索能力
提供了通用的MCP工具加载函数,便于扩展更多第三方服务
4. MCP客户端 (mcp_client.py)
连接到天气服务器并使用其提供的工具。通过SSE(Server-Sent Events)协议与服务器通信,处理连接和重试逻辑。
5. 综合代理 (agent_with_diverse_tools.py)
核心组件,整合所有来源的工具:
自定义本地工具:数学计算、字符串处理
本地MCP服务工具:天气查询服务
第三方MCP工具:智谱Web搜索
使用LangGraph的React Agent架构
基于Moonshot API实现
Related MCP server: Weather MCP Server
使用方法
安装依赖
pip install -r requirements.txt环境配置
在.env文件中设置以下变量:
MOONSHOT_API_KEY: Moonshot API密钥(用于LLM)ZHIPU_API_KEY: 智谱API密钥(用于Web搜索服务)
启动服务
启动天气服务器
python weather/weather.py运行综合代理测试
python weather/agent_with_diverse_tools.py测试智谱Web搜索工具
python weather/mcp_third_party.py示例查询
综合代理可以处理多种类型的查询:
数学计算:
"计算 23 + 45 的结果"
"计算 16 的平方根"
"计算 7 * 8 然后减去 10"
字符串处理:
"将 'hello world' 转换为大写"
"将 ['我', '爱', '中国'] 用空格连接起来"
天气信息:
"纽约州有什么天气警报?"
"旧金山的天气预报是什么?"
"加利福尼亚州有什么严重天气警报?"
Web搜索:
"中国最近的航天成就有哪些?"
"2024年世界经济论坛的主要议题是什么?"
"最新的人工智能研究进展有哪些?"
混合查询:
"计算 7 * 8 然后减去 10,并查询一下上海的天气预报"
系统特点
模块化设计:各个工具源相互独立,便于维护和扩展
容错能力:即使某个服务不可用,系统仍能使用其他可用工具
可扩展性:容易添加新的工具源和功能
多源整合:将不同来源和类型的工具统一到一个代理中
扩展方向
添加更多第三方MCP服务
实现工具调用的可视化界面
增加用户交互模式(如对话模式)
添加更多领域的专业工具
注意事项
确保在运行代理前先启动天气服务器
服务器默认在
localhost:8000上运行天气数据来自美国国家气象局(NWS)API
智谱Web搜索需要有效的API密钥
系统架构
技术栈
Python 3.11+
MCP (Model Control Protocol)
FastMCP 服务器
LangGraph + LangChain
SSE (Server-Sent Events) 传输
安装
克隆仓库:
git clone https://github.com/haichaozheng/weather-mcp.git cd weather-mcp创建虚拟环境:
# 使用 Python 标准库 python -m venv weather_venv # 激活虚拟环境(Windows) weather_venv\Scripts\activate # 激活虚拟环境(Linux/Mac) source weather_venv/bin/activate安装依赖:
pip install -r requirements.txt配置环境变量:
创建
.env文件,参考.env.example文件格式添加必要的 API 密钥
项目结构
weather-mcp/ ├── weather/ │ ├── weather.py # 主服务器文件 │ ├── mcp_client.py # 客户端测试文件 ├── requirements.txt # 项目依赖 ├── .env.example # 环境变量示例 └── README.md # 本文档
## 环境变量配置
项目使用 `.env` 文件存储环境变量和敏感信息。请按照以下步骤设置:
1. 复制环境变量模板文件:
```bash
cp .env.example .env编辑
.env文件,填入您的实际配置:MOONSHOT_API_KEY=your_actual_api_key确保
.env文件不会被提交到版本控制系统中
环境变量
在.env文件中设置以下变量:
MOONSHOT_API_KEY: Moonshot API密钥
注意事项
确保在运行代理前先启动天气服务器
服务器默认在
localhost:8000上运行天气数据来自美国国家气象局(NWS)API
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/haichaozheng/weather-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server