Enables environment variable configuration management through .env files, supporting the storage and management of API keys and configuration settings.
Supports Node.js dependencies for certain functionality, with package.json configuration for managing Node.js packages.
Provides integration with OpenAI API for client connectivity, supporting natural language interactions through OpenAI's language models to understand user intent and generate responses.
Includes testing support with pytest for development and quality assurance of the weather service functionality.
Uses Python for the server implementation, providing the runtime environment for the weather query service.
Uses TOML for Python project configuration, managing dependencies and project metadata through pyproject.toml.
Weather MCP (Model Context Protocol) 天气查询服务
🌤️ 服务介绍
Weather MCP 是一个基于 Model Context Protocol (MCP) 的天气查询服务,通过集成 OpenWeather API 提供全球天气信息查询功能。该服务支持自然语言交互,用户可以用中文描述需求,系统会自动调用相应的天气查询工具并返回格式化的天气信息。
📋 服务描述
主要功能
- 全球天气查询: 支持查询全球任意城市的实时天气信息
- 多语言支持: 支持中文查询和中文天气描述
- 智能交互: 通过大语言模型理解用户意图,自动调用天气查询工具
- 格式化输出: 提供美观易读的天气信息展示
技术特点
- 基于 MCP 协议,支持与各种 AI 客户端集成
- 异步 HTTP 请求,提高响应速度
- 完善的错误处理和容错机制
- 支持 stdio 通信方式
🏗️ 类型
服务类型
- MCP Server: 提供天气查询工具的 MCP 服务器
- MCP Client: 支持与大语言模型交互的客户端
- API Integration: 集成 OpenWeather API 的天气数据服务
架构类型
- 微服务架构: 服务器和客户端分离,支持独立部署
- 异步架构: 基于 asyncio 的异步处理
- 协议驱动: 基于 MCP 协议的标准化通信
⚙️ 服务配置
服务器配置 (server.py)
客户端配置 (client.py)
项目依赖配置
Python 依赖 (pyproject.toml)
Node.js 依赖 (package.json)
🔧 环境变量配置
必需环境变量
创建 .env
文件并配置以下环境变量:
环境变量说明
变量名 | 描述 | 示例值 | 是否必需 |
---|---|---|---|
OPENAI_API_KEY | OpenAI API 密钥 | sk-... | ✅ 必需 |
BASE_URL | OpenAI API 基础 URL | https://api.openai.com/v1 | ✅ 必需 |
MODEL | 使用的 OpenAI 模型 | gpt-3.5-turbo | ✅ 必需 |
获取 API 密钥
OpenAI API Key
- 访问 OpenAI Platform
- 登录或注册账号
- 进入 API Keys 页面
- 创建新的 API Key
- 复制密钥到
.env
文件
OpenWeather API Key
- 访问 OpenWeather API
- 注册免费账号
- 获取 API Key
- 在
server.py
中替换API_KEY
变量
🚀 快速开始
1. 安装依赖
2. 配置环境变量
3. 启动服务器
4. 运行客户端
5. 开始使用
📁 项目结构
🔍 API 文档
可用工具
query_weather
- 描述: 查询指定城市的天气信息
- 参数:
city
(string): 城市名称(英文)
- 返回: 格式化的天气信息字符串
使用示例
🛠️ 开发指南
添加新的天气工具
- 在
server.py
中添加新的工具函数 - 使用
@mcp.tool()
装饰器注册工具 - 实现工具逻辑和错误处理
- 更新文档和测试
自定义配置
可以通过修改 config.py
文件来自定义服务配置:
📝 许可证
本项目采用 MIT 许可证。详见 LICENSE 文件。
🤝 贡献
欢迎提交 Issue 和 Pull Request 来改进这个项目!
📞 支持
如果你遇到问题或有建议,请:
- 查看 Issues
- 创建新的 Issue
- 联系项目维护者
注意: 请确保妥善保管你的 API 密钥,不要将其提交到版本控制系统中。
🔧 标准服务配置
字段说明
"args"
:传递给 MCP 服务器的参数(如server.py
)。"command"
:启动命令(Python 项目用"python"
)。"env"
:自动提取的环境变量,请将your_openai_api_key_here
和your_openweather_api_key_here
替换为你自己的密钥。
如需多个服务配置,可以用 JSON 数组格式填写多个 mcpServers
。
如需进一步定制或有其他字段需求,请告知!
This server cannot be installed
A Model Context Protocol server that enables natural language weather queries for global cities, integrating with OpenWeather API to provide real-time weather information in an easy-to-read format.
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server that retrieves current weather information for specified cities using the Open-Meteo API, requiring no API key.Last updated -312PythonApache 2.0
- -securityFlicense-qualityA Model Context Protocol server that provides current weather information and 3-day forecasts for specified cities using the Open-Meteo API.Last updated -Python
- -securityFlicense-qualityA production-ready Model Context Protocol server that provides weather data from OpenWeatherMap API, allowing users to query current weather by city name or coordinates with support for different temperature units.Last updated -Python
- AsecurityFlicenseAqualityA Model Context Protocol server that provides real-time weather information and 5-day forecasts to AI assistants, supporting multiple languages and flexible units.Last updated -38TypeScript