使用说明
Weather API MCP Server
一个轻量级的模型上下文协议(MCP)服务器,使像Claude这样的AI助手能够检索并解释实时天气数据。
在Claude桌面版上安装
要在Claude Desktop中使用您的MCP服务器,请将其添加到您的Claude配置中:
1. 本地模式
{
"mcpServers": {
"weather-mcp-server": {
"command": "/path/to/weather-mcp-server",
"env": {
"WEATHER_API_KEY": "your-api-key"
}
}
}
}
您可以在个人账户中获取API密钥 WeatherAPI(天气应用程序编程接口)。
2. 远程模式
{
"mcpServers": {
"weather-mcp-server": {
"url": "http://host:port/sse"
}
}
}
从源代码构建
你可以使用 go 在(指定位置)构建二进制文件 cmd/github-mcp-server 目录。
go build -o weather-mcp-server ./cmd/weather-mcp-server
使用MCP与Docker容器
1. 构建Docker镜像:
docker build -t weather-mcp-server .
2. 运行Docker容器:
docker run -e WEATHER_API_KEY=your-api-key -d --name weather-mcp-server -p 8000:8000 weather-mcp-server
替换 your-api-key 根据你的实际情况 WeatherAPI(天气应用程序编程接口) API密钥。
工具
-
当前天气 - 获取某个城市的当前天气
city城市名称(字符串,必填)
项目结构
该项目被组织成几个关键目录:
├── cmd
│ └── weather-mcp-server
├── internal
│ └── server
│ ├── handlers # MCP handlers
│ ├── services # Business logic layer
│ │ ├── core # Core application logic
│ │ └── mock # Mock services for testing
│ ├── tools # MCP tools
│ └── view # Templates for displaying messages
└── pkg
测试
如果你正在添加新功能,请务必为它们编写测试。
1. 安装mockgen工具:
go install go.uber.org/mock/mockgen@latest
参见安装指南 go.uber.org/mock 翻译为中文是:“Uber 的 Go 语言 mock 包”。
2. 使用以下命令生成模拟文件:
make generate-mocks
3. 运行单元测试:
make run-tests
贡献;助力
欢迎随时提交问题或发送包含改进的拉取请求。提前感谢您的帮助!
请遵循 贡献指南.
许可证
这台MCP服务器已获得以下授权/许可: 麻省理工学院许可证。