英国天气MCP服务器
从Antrhropic代码开始 构建MCP客户端 MCP文档中的页面,这是一个可以查看的游乐场 MCP协议等。
适应英国天气
删除了美国特定代码,并用以下代码替换 OpenWeatherMapOpenWeatherMap支持 任何全球位置。对于想要输入银行卡详细信息的人,有一个 在付款之前,将服务范围扩大到慷慨的限度。或者,和我一样,你可以 API密钥,没有银行卡详细信息,只访问一个服务;以检索某个位置的当前天气。
一个示例调用是
https://api.openweathermap.org/data/2.5/weather?lat=51.5234&lon=0.1167&units=metric&appid={API-key}
例如,返回此JSON
{
"coord": {
"lon": 0.1167,
"lat": 51.5234
},
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02d"
}
],
"base": "stations",
"main": {
"temp": 16.31,
"feels_like": 16.09,
"temp_min": 15.45,
"temp_max": 17.12,
"pressure": 1007,
"humidity": 80,
"sea_level": 1007,
"grnd_level": 1005
},
"visibility": 10000,
"wind": {
"speed": 4.12,
"deg": 240
},
"clouds": {
"all": 20
},
"dt": 1763032792,
"sys": {
"type": 1,
"id": 1414,
"country": "GB",
"sunrise": 1763018062,
"sunset": 1763050408
},
"timezone": 0,
"id": 6690871,
"name": "Dagenham",
"cod": 200
}配置Claude Desktop以使用服务器
有关Mac/Linux和Windows的详细信息,请访问上面的URL。我自己的cofig为克劳德桌面上 MacOS在 ~/Library/Application\ Support/Claude/claude_desktop_config.json 是
{
"mcpServers": {
"weather": {
"command": "/opt/homebrew/bin/uv",
"args": [
"--directory",
"/Users/mark/PycharmProjects/MSc/WeatherMCP/",
"run",
"weather.py"
]
}
}
}显然,您将需要一个Anthropic API密钥,需要订阅。据我回忆,我刚刚登录 我在Claude Desktop上的Anthropic帐户,那个动作抓住了我 API密钥。
你可能有兴趣阅读 Reddit上关于使用MCP服务器的帖子. 包含 tavily 这在我的清单上。 警告,写于2025年3月左右。
为聊天机器人/MCP客户端示例配置MCP服务器
使用(我的示例仓库)中的代码\[https://github.com/markvan/MCPclient\]使用 Python 3、聊天机器人/MCP客户端脚本和MCP服务器的路径,例如。
python client.py ../WeatherMCP/weather.py
