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! ๐ฆ๏ธโ๏ธ
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.