使用说明
气象MCP服务器文档
概述
气象MCP服务器是一个。NET 8应用程序,该应用程序公开MCP工具,用于使用OpenWeatherMap API访问实时天气数据、预报和警报。它旨在与AI助手和MCP客户端集成。
MCP工具
1.GetCurrentWeather
说明:
检索指定城市的当前天气状况。
签字:
GetCurrentWeather(string city, string? countryCode = null)
参数:
city:城市名称(例如“伦敦”)countryCode(可选):国家代码(例如“GB”、“US”)
退货:
当前天气(温度、条件)摘要
2.天气预报
说明:
提供指定城市给定天数的天气预报(至少3天预报)。
签字:
GetWeatherForecast(string city, string? countryCode = null, int days = 3)
参数:
city:城市名称countryCode(可选):国家代码days:预测的天数(默认值:7)
退货:
每日预报摘要(温度、条件等)
3.获取天气警报
说明:
返回指定城市的天气警报或警告(如果可用)。
签字:
GetWeatherAlerts(string city, string? countryCode = null)
参数:
city:城市名称countryCode(可选):国家代码
退货:
活动天气警报或警告列表。
设置和启动说明(VS代码)
1.克隆存储库
git clone https://github.com/azamatsalamat/WeatherMcpServer
cd WeatherMcpServer
2.在VS Code中打开项目
- 启动VS Code并打开
WeatherMcpServer文件夹。
3.使用配置API密钥 .vscode/mcp.json
创建一个名为的文件 .vscode/mcp.json 在项目根目录中包含以下内容:
{
"servers": {
"WeatherMcpServer": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"WeatherMcpServer.csproj"
],
"env": {
"OPENWEATHERMAP_API_KEY": "<your-api-key>",
"OPENWEATHERMAP_BASE_URL": "https://api.openweathermap.org"
}
}
}
}
插入您自己的OpenWeatherMap API密钥。
4.建设项目
在VS Code中打开集成终端并运行:
dotnet build
5.启动MCP服务器
- 按“WeatherMcpServer”部分上方mcp.json中的“开始”按钮。
6.与MCP工具交互
使用MCP客户端或AI助手(如CoPilot)调用上述工具。
故障排除
- 确保您的API密钥有效并且存在于
.vscode/mcp.json - 检查
logs/错误详细信息目录 - 确保。NET 8.0已安装