天气查询 MCP 服务器/客户端示例
该项目是一个天气查询客户端,它与 MCP(模型客户端协议)服务器交互以获取并显示指定城市的天气信息。
特征
连接到 MCP 服务器以列出可用的工具。
查询指定城市的天气信息。
显示格式化的天气信息,包括温度、湿度、风速和天气描述。
要求
Python 3.8+
openai
库dotenv
库mcp
库
设置
克隆存储库:
git clone <repository_url> cd <repository_directory>创建虚拟环境并激活它:
python -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate`安装所需的依赖项:
pip install -r requirements.txt在根目录中创建一个
.env
文件并添加您的 OpenAI API 密钥和其他配置:OPENAI_API_KEY=<your_openai_api_key> BASE_URL=<your_base_url> MODEL=<your_model>
用法
启动 MCP 服务器:
python server.py运行客户端并连接服务器:
python client.py <path_to_server_script>与客户互动:
输入英文城市名称即可获取天气信息。
输入
quit
退出客户端。
项目结构
server.py
:包含 MCP 服务器实现和天气查询工具。client.py
:包含与服务器交互的 MCP 客户端实现。.env
:API 密钥和配置的环境变量。.gitignore
:指定 git 要忽略的文件和目录。README.md
:项目文档。
执照
该项目已获得 MIT 许可。
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
MCP 服务器实现允许用户获取和显示指定城市的天气信息,包括温度、湿度、风速和天气描述。
Related MCP Servers
- AsecurityAlicenseAqualityAn MCP server that provides real-time weather information including temperature, humidity, wind speed, and sunrise/sunset times through the OpenWeatherMap API.Last updated -12MIT License
- -securityAlicense-qualityAn MCP server that connects to OpenWeatherMap's API to provide current weather data and multi-day forecasts for locations worldwide in different measurement units.
- AsecurityFlicenseAqualityA simple MCP server that provides a tool to fetch current weather information for cities using the Open-Meteo API, communicating through stdin/stdout.Last updated -12
- -securityFlicense-qualityAn MCP server that provides weather information like forecasts and alerts for US locations using the National Weather Service API.Last updated -4