使用说明
MCP气象服务
使用模型上下文协议(MCP)构建的天气服务,使用WeatherAPI.com为印度城市提供当前天气和预报。
先决条件
- Python 3.13或更高版本
- 紫外线 包管理器
- WeatherAPI.com API密钥
- Groq API密钥(用于聊天界面)
- Claude for Desktop(用于与Claude一起测试)
安装
- 克隆存储库:
git clone <your-repo-url>
cd mcp-server
- 创建一个
.env使用API密钥在项目根目录中创建文件:
# WeatherAPI.com API Key
WEATHER_API_KEY=your_weather_api_key_here
# Groq API Key
GROQ_API_KEY=your_groq_api_key_here
- 使用uv安装依赖项:
uv pip install -e .
运行服务
发展模式
要在开发模式下运行气象服务:
uv run mcp dev server/weather.py
安装并运行
要在桌面claude上安装并运行该服务,请执行以下操作:
uv run mcp install server/weather.py
设置weather.json
这 weather.json 聊天界面需要配置文件。
1、使用Claude for Desktop测试您的服务器:
- 打开VS Code并运行:
code $env:AppData\Claude\claude_desktop_config.json - 添加以下配置:
{ "mcpServers": { "weather": { "command": "uv", "args": [ "--directory", "C:\\ABSOLUTE\\PATH\\TO\\YOUR\\mcp-server", "run", "server/weather.py" ] } } } - 替换
C:\\ABSOLUTE\\PATH\\TO\\YOUR\\mcp-server使用您的实际项目路径
-
对于聊天界面(client.py):
- 这
weather.json文件应该在你的server目录 - 确保它包含:
{ "mcpServers": { "weather": { "command": "uv", "args": [ "--directory", "C:\\ABSOLUTE\\PATH\\TO\\YOUR\\mcp-server", "run", "server/weather.py" ] } } } - 替换
C:\\ABSOLUTE\\PATH\\TO\\YOUR\\mcp-server使用您的实际项目路径
- 这
-
更改后重新启动Claude for Desktop
使用聊天界面
运行聊天客户端与天气服务进行交互:
python server/client.py
聊天界面支持:
- 获取印度任何城市的当前天气
- 获取三天天气预报
- 关于天气的自然语言查询
命令:
- 键入“exit”或“quit”结束对话
- 键入“clear”以清除对话历史记录
特性
-
当前天气信息:
- 温度(摄氏度)
- 天气条件
- 湿度
- 风速
- 上次更新时间戳
-
三天天气预报:
- 每日高温和低温
- 天气情况
- 特定日期的预测
项目结构
mcp-server/
├── server/
│ ├── weather.py # Weather service implementation
│ ├── client.py # Chat interface
│ └── weather.json # MCP server configuration
├── .env # API keys configuration
├── pyproject.toml # Project dependencies
└── README.md # This file
API密钥
-
WeatherAPI.com:
- 注册地址: WeatherAPI.com 网站
- 获取免费的API密钥
- 添加到
.env像WEATHER_API_KEY
-
绿色API:
- 注册地址: Groq 控制台
- 获取API密钥
- 添加到
.env像GROQ_API_KEY
贡献
请随时提交问题和增强请求!