Go温度服务器
这是一个简单的基于Go-based的MCP服务器,通过REST API提供给定位置的当前温度。
用法
- 设置您的OpenWeatherMap API密钥 作为环境变量(见下文),或将其作为
appidAPI的查询参数。
- 运行服务器:
go run main.go- 查询温度端点:
# Using environment variable for API key
curl 'http://localhost:8080/temperature?location=London'
# OR, pass API key as a query parameter
curl 'http://localhost:8080/temperature?location=London&appid=your_api_key_here'天气API关键
此服务器需要天气提供商的API密钥(例如,OpenWeatherMap)。你可以:
- 将其设置为环境变量:
export WEATHER_API_KEY=your_api_key_here- 或者将其作为
appid请求中的查询参数:
curl 'http://localhost:8080/temperature?location=London&appid=your_api_key_here'配置
PORT(可选):运行服务器的端口(默认值:8080)WEATHER_API_KEY:您的天气API密钥(如果您提供,则为可选appid作为查询参数)
