天气数据服务

一个基于Python的MCP服务器,用于获取天气数据,可与GitHub Copilot或Claude Desktop等MCP客户端集成。

  • by Anshul619
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Anshul619/weather-mcp

使用说明

WeatherMCP服务器

  • 基于Python的MCP(模型代码提供程序)该服务器与MCP客户端(GitHub Copilot或Claude Desktop)集成,作为获取天气数据的工具。
  • 它使用Python构建,作为本地标准I/O服务器运行,可以在各种MCP客户端中配置,如VS Code的MCP.json或Claude Desktop的.MCP.json。
  • 阅读更多

高级设计

实际演示(使用Claude Desktop)

示例提示

get_weather {"city": "London"} # Retrieves current weather conditions.

get_forecast {"city": "London"} # Provides a short-term weather forecast.

get_alerts {"state": "CA"} # Fetches alerts for a specific region (e.g., US state).

Ask the WeatherMCP server for the weather in London.

设置气象MCP服务器

克隆存储库

git clone https://github.com/Anshul619/weather-mcp-server
cd weather-mcp-server

创建并激活虚拟环境

python3 -m venv .venv
source .venv/bin/activate

再进行

pip install -r requirements.txt

运行服务器

source .venv/bin/activate
python weather_server.py

为Claude Desktop配置(可选)

  • 将以下JSON添加到 claude_desktop_config.json 文件。
  • 阅读更多
{
  "mcpServers": {
		"WeatherMCP": {
			"type": "stdio",
			"command": "<path>/weather-mcp/.venv/bin/python3",
			"args": [
				"<path>/weather-mcp/weather_server.py"
			]
		}
	}
}

为Copilot配置(通过可视化代码)

  • 如果你使用VS Code GitHub Copilot,将以下配置添加到您的 ~/.vscode/mcp.json 文件并重新启动VS代码。
  • 阅读更多
{
  "servers": {
		"WeatherMCP": {
			"type": "stdio",
			"command": "<path>/weather-mcp/.venv/bin/python3",
			"args": [
				"<path>/weather-mcp/weather_server.py"
			]
		}
	}
}

验证Copilot是否看到您的MCP服务器

  • 打开VS代码命令面板(Mac上为Cmd+Shift+P,Windows上为Ctrl+Shift+P)。
  • 搜索 Copilot: List MCP Servers (此命令是在MCP支持发布时添加的)。
  • 您应该在列表中看到WeatherMCP。

如果缺失:

  • 检查你的 ~/.vscode/mcp.json 路径是正确的。
  • 检查日志: 视图 → 输出 → 副驾驶(下拉菜单) 对于MCP错误。

调试提示

  • 如果Copilot未显示您的服务器:请检查 ~/.vscode/mcp.json 语法(必须是有效的JSON)。
  • 如果服务器崩溃:运行 python weather_server.py 在终端中手动查看错误。
  • 您还可以添加调试 print() 来电 handle_tool_call 查看传入的请求。