气象MCP服务器
   ](https://hub.docker.com/) 
一个全面的、可用于生产的MCP(模型上下文协议)服务器,提供来自美国国家气象局API的天气数据,包括缓存、监控、强大的错误处理和全面的测试。
🚀 快速开始
# Install dependencies
uv sync --group dev
# Run the weather MCP server
uv run weather-mcp
# or
uv run -m src.main
# Run tests
uv run pytest tests/ -v
# Run code quality checks
ruff check --fix && ruff format📁 项目结构
mcp-server-weather-py/
├── 📄 Core Application
│ └── src/
│ ├── main.py # Main entry point
│ ├── client.py # HTTP client with caching
│ ├── config.py # Configuration management
│ ├── exceptions.py # Custom exception classes
│ ├── formatters.py # Data formatting utilities
│ ├── models.py # Data models and types
│ ├── tools.py # MCP tools implementation
│ ├── validators.py # Input validation
│ └── weather.py # Alternative entry point
│
├── 🧪 Testing & Quality
│ └── tests/
│ ├── test_client.py # HTTP client tests
│ ├── test_config.py # Configuration tests
│ ├── test_exceptions.py # Exception handling tests
│ ├── test_formatters.py # Data formatting tests
│ ├── test_models.py # Data model tests
│ ├── test_tools.py # MCP tools tests
│ ├── test_validators.py # Validation tests
│ └── test_weather.py # Main module tests
│
├── 🐳 Deployment
│ ├── Dockerfile # Container configuration
│ ├── docker-compose.yml # Multi-service orchestration
│ └── .dockerignore # Container build optimization
│
├── 📚 Configuration & Documentation
│ ├── pyproject.toml # Package configuration & dependencies
│ ├── CLAUDE.md # Development guide
│ ├── MCP_SETUP.md # MCP integration guide
│ └── docs/README_ENHANCED.md # Detailed enhancement documentation
│
└── 📄 Examples & Utilities
├── examples.py # Usage examples & demos
├── example_state_machine.py # Educational state machine example
└── setup_script.py # Setup automation script✨ 特性
- 🛡️ 稳健的错误处理:具有重试逻辑的自定义异常层次结构
- ⚡ 演出:具有TTL和速率限制的内存缓存
- 📊 监控:健康检查和结构化日志记录
- 🧪 综合测试:8个模块的测试覆盖率超过95%
- 🐳 生产就绪:Docker支持和部署配置
- 🔧 可配置的:基于环境的配置
- 🌐 MCP集成:已准备好集成Claude Code
🛠️ api参考
核心MCP工具
get_alerts(state, severity_filter=None):通过可选的严重性过滤获取天气警报get_forecast(latitude, longitude):获取特定坐标的天气预报get_location_forecast(city, state):按城市和州获取天气预报health_check():检查服务器运行状况和性能指标
🧪 测试
# Run all tests with coverage
uv run pytest tests/ -v --cov=. --cov-report=html
# Run specific test modules
uv run pytest tests/test_validators.py -v
uv run pytest tests/test_tools.py -v测试覆盖率:8个模块的46个测试,涵盖验证、数据模型、HTTP客户端、MCP工具、格式化、异常和配置。
🐳 部署
地方发展
uv sync --group dev
uv run weather-mcpDocker部署
docker build -t weather-mcp .
docker run -it weather-mcp使用Docker Compose进行生产
docker-compose up -d🔗 MCP集成
连接到Claude Code进行交互式天气查询。看 MCP_SETUP.md 有关完整的设置说明。
📚 文档
快速参考
- CLAUDE.md:包含命令和架构细节的开发指南
- MCP_SETUP.md:Claude Code集成说明
- examples.py:交互式使用演示
综合文档
- 📖 维基工程:完整的文件,包括:
______________________________________________________________________
气象MCP服务器 -大型语言模型的生产就绪天气数据🌤️
