MCP Weather Agent
Enables natural language weather queries for Israel and the USA, fetching real-time forecasts and alerts via web scraping and official APIs.
README
🌤️ MCP Weather Agent
An intelligent, multi-region weather assistant powered by OpenAI and the Model Context Protocol (MCP).
Get real-time weather forecasts and alerts for Israel and the United States through a natural language chat interface. The agent intelligently routes questions to the appropriate data source and compiles answers from live web data and official weather APIs.
✨ Features
- 🤖 AI-Powered Chat: Conversational weather queries using GPT-4o-mini
- 🌍 Dual Data Sources:
- 🇮🇱 Israel: Live web scraping from Weather2day via Playwright
- 🇺🇸 USA: Official National Weather Service API
- 🔄 Smart Tool Routing: The agent automatically selects the right tool based on your question
- 💬 Natural Language: Ask questions in plain English; the agent understands context and intent
- 🔐 Secure: API keys stored in
.envand excluded from version control - 🎯 Interactive: Real-time chat loop with visible browser automation for Israel queries
📋 Table of Contents
- Quick Start
- Requirements
- Setup
- Running the Agent
- Architecture
- Example Queries
- Troubleshooting
- FAQ
- Security
🚀 Quick Start
Get up and running in 3 minutes:
# 1. Install dependencies
uv sync
uv run playwright install chromium
# 2. Create .env file with your OpenAI API key
copy .env.example .env
# Edit .env and add: OPENAI_API_KEY=sk-...
# 3. Run the agent
uv run .\host.py
# 4. Ask a weather question!
# Example: "What is the weather forecast for Jerusalem?"
📦 Requirements
| Component | Version | Purpose |
|---|---|---|
| Python | 3.13+ | Runtime environment |
| OpenAI API Key | — | GPT-4o-mini model access |
| uv | Latest | Fast Python package manager |
| Chromium | Latest | Browser automation (Playwright) |
| Internet | — | API access and web scraping |
🔧 Setup
1. Install Dependencies
Open a terminal in the project directory and run:
# Install Python dependencies
uv sync
# Download Chromium browser for Playwright (required for Israel weather)
uv run playwright install chromium
First time taking a while? Yes—Playwright downloads Chromium (~300 MB). This is a one-time operation.
2. Configure OpenAI API Key
Create a .env file in the project root:
# Option A: Copy the template
copy .env.example .env
# Option B: Create manually
echo OPENAI_API_KEY=your_openai_api_key > .env
Replace your_openai_api_key with your actual OpenAI API key from platform.openai.com/account/api-keys.
⚠️ Important: Never commit .env or share your API key. The .gitignore already excludes it.
3. Verify Installation
Test the setup:
uv run .\host.py
You should see:
Connected to server with tools: [...]
MCP Client Started!
Type your queries or 'quit' to exit.
Query:
Press Ctrl+C or type quit to exit.
▶️ Running the Agent
Start the interactive chat:
uv run .\host.py
The agent launches in interactive mode. Type a weather question and press Enter. The agent will:
- ✅ Parse your question
- 🔍 Route to the appropriate weather tool (Israel or USA)
- 🌐 Fetch real-time data (may open a browser window for Israel)
- 📊 Process and format the response
- 💬 Return the answer
Type quit to exit.
For Israel queries: A Chromium browser window opens automatically. This is normal—the agent is using Playwright to interact with Weather2day. The window closes when the query completes.
🏗️ Architecture
┌─────────────────────────────────────────────────────────────────┐
│ OpenAI (GPT-4o-mini) │
│ (Tool Selection & Reasoning) │
└────────────────────────────┬────────────────────────────────────┘
│
┌────────────┴────────────┐
│ │
┌───────▼────────┐ ┌───────▼────────┐
│ MCP Host │ │ MCP Host │
│ (client.py) │ │ (client.py) │
└───────┬────────┘ └───────┬────────┘
│ │
┌───────▼──────────────┐ ┌──────▼─────────────┐
│ weather_Israel.py │ │ weather_USA.py │
│ (Playwright + Web) │ │ (NWS API) │
└───────┬──────────────┘ └──────┬─────────────┘
│ │
┌───────▼──────────────┐ ┌──────▼─────────────┐
│ Weather2day.co.il │ │ api.weather.gov│
│ (Live Web Browser) │ │ (REST API) │
└──────────────────────┘ └───────────────────┘
Data Flow:
- You ask a question in the chat
- The host sends it to OpenAI with available tools
- OpenAI selects which tool to call based on the question
- The appropriate MCP server executes and returns data
- The host formats and returns the answer
💬 Example Queries
🇮🇱 Israel Weather
What is the weather forecast for Jerusalem?
Give me the forecast for Tel Aviv.
What is the weather like in Haifa today?
Show me the forecast for Eilat.
What is the weather in Beer Sheva?
Is it going to rain in Kfar Saba tomorrow?
Tell me about the weather in Nazareth.
What's the forecast for Tiberias?
Supported Cities: Jerusalem, Tel Aviv, Haifa, Eilat, Beer Sheva, Kfar Saba, Tiberias, Nazareth, and most major Israeli cities recognized by Weather2day.
🇺🇸 USA Weather
What is the weather forecast for New York City? (40.7128, -74.0060)
What's the weather at latitude 34.0522, longitude -118.2437? (Los Angeles)
Are there any active weather alerts in California?
What weather alerts are in effect in New York?
Give me the forecast for Chicago coordinates. (41.8781, -87.6298)
Are there any severe weather warnings in Texas?
Format:
- Forecasts: Use latitude/longitude coordinates
- Alerts: Use two-letter state codes (
CA,NY,TX, etc.)
🎯 Smart Agent Behavior
The agent understands context:
- ✅ "What's the weather in Jerusalem?" → Uses Israel tool
- ✅ "I'm visiting New York, what's the forecast?" → Uses USA tool (40.71, -74.01)
- ✅ "Tell me about weather in Tel Aviv and Los Angeles" → Calls both tools
- ✅ "Is it raining in Chicago right now?" → Routes to USA tool
📂 Project Structure
MCP Weather/
├── host.py # Main chat host (OpenAI + tool orchestration)
├── client.py # MCP client connector
├── weather_Israel.py # Israel MCP server (Playwright + Web)
├── weather_USA.py # USA MCP server (NWS API)
├── pyproject.toml # Dependencies and project metadata
├── uv.lock # Locked dependency versions
├── .env.example # Template for environment variables
├── .env # Your API keys (git-ignored)
├── README.md # This file
└── .gitignore # Git exclusion rules
🐛 Troubleshooting
❌ OPENAI_API_KEY is missing
Problem: The agent can't find your API key.
Solution:
- Verify
.envexists in the project root (same folder ashost.py) - Check the file contains:
OPENAI_API_KEY=sk-your-actual-key-here - Restart the host:
uv run .\host.py
❌ Chromium browser won't launch
Problem: "Failed to launch browser" error.
Solution:
uv run playwright install chromium
If still failing, check disk space (Chromium needs ~500 MB).
❌ Connection timeout or API errors
Problem: "net::ERR_CONNECTION_RESET" or request failures.
Solution:
- Check your internet connection
- Verify your OpenAI API key is valid at platform.openai.com
- Check API usage and billing
❌ Israel browser opens but search fails
Problem: City search doesn't return suggestions.
Explanation: The Weather2day autocomplete only works on the /forecast page. The tool automatically returns to that page before each search, but if it fails:
Solution:
- Verify Chromium is up to date:
uv run playwright install --with-deps chromium - Ensure you have internet connectivity to
weather2day.co.il - Check for browser pop-ups or cookie banners (the agent handles these, but very slow connections may timeout)
❌ "A server fails to connect"
Problem: MCP server connection error.
Solution:
# Run from the project directory
Set-Location .\project-template
uv run .\host.py
❓ FAQ
Q: How does the agent decide which tool to use?
A: OpenAI's GPT-4o-mini reads your question and selects the best tool based on the context (country/region mentioned, coordinates provided, etc.). It's not rule-based—it uses language understanding.
Q: Can I ask about multiple regions in one query?
A: Yes! The agent can call multiple tools. Try: "What's the weather in Tel Aviv and New York?"
Q: Why does the Israel browser open visibly?
A: Playwright automates Weather2day by typing into the live search, selecting results, and reading the page. Headless mode (invisible) doesn't work with this site's JavaScript-heavy autocomplete, so the browser runs visibly.
Q: How much does this cost?
A: You're billed by OpenAI based on API calls. Each query costs ~$0.001–$0.01 depending on response length. Israel web scraping is free; USA API is free (NWS is public).
Q: What if I want to add more regions?
A: Create a new MCP server (e.g., weather_Europe.py) and register it in host.py under self.mcp_clients. See the existing servers for the pattern.
Q: Is my API key safe?
A: Yes. Your .env is excluded from Git and stored locally only. Never paste your key in code or public chat.
Q: Can I use this in production?
A: This is a demo project. For production:
- Use async request queuing
- Add logging and error recovery
- Cache forecasts (weather changes hourly, not per-query)
- Set up monitoring and alerts
- Use environment-based configuration
🔒 Security
| ⚠️ Do | ❌ Don't |
|---|---|
✅ Keep .env local and private |
❌ Commit .env to Git |
| ✅ Rotate API keys regularly | ❌ Share your API key |
| ✅ Use environment variables in production | ❌ Hardcode secrets in code |
| ✅ Check API billing limits | ❌ Leave quota unlimited |
| ✅ Use HTTPS for API calls | ❌ Use HTTP in production |
If your API key is exposed:
- Revoke it immediately in OpenAI Dashboard
- Generate a new key
- Update
.env
📝 License
This project is provided as-is for educational purposes. See LICENSE for details.
🤝 Contributing
Have ideas to improve the agent? Contributions are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📞 Support
- 🐛 Report bugs via GitHub Issues
- 💡 Suggest features in Discussions
- 📧 For security issues, email privately (do not open a public issue)
Happy forecasting! 🌦️☀️
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。