Skip to main content
Glama
Efrat-Fr

Weather-MCP

by Efrat-Fr
README.md
# šŸŒ¤ļø — ×Ŗ×—×–×™×Ŗ מזג אוויר ×‘×™×©×Ø××œ

×¤×Ø×•×™×§×˜ לימוד בפיתוח **MCP (Model Context Protocol)**: הוכן (Agent) מבוהה LLM שיודע לשלוף ×Ŗ×—×–×™×Ŗ מזג אוויר ×œ×¢×Ø×™× ×‘×™×©×Ø××œ ובארה"ב, ×•×œ×¢× ×•×Ŗ עליה בשפה חופשית בצ'אט ×©×‘×˜×Ø×ž×™× ×œ.

---

## šŸŽÆ ×ž×˜×Ø×Ŗ ×”×¤×Ø×•×™×§×˜

×œ×‘× ×•×Ŗ שרת MCP ייעודי ש"מלמד" את ה-LLM לבצע משימה שהוא לא יודע לבד — לשלוף ×Ŗ×—×–×™×Ŗ מזג אוויר ×ž××Ŗ×Ø ×™×©×Ø××œ×™ שאין לו API.

ההוכן עושה זאת בשתי ×“×Ø×›×™×:

1. **שרת ×™×©×Ø××œ (`weather-Israel`)** — מאטמט דפדפן ××ž×™×Ŗ×™ עם **Playwright**: פותח את [weather2day.co.il/forecast](https://www.weather2day.co.il/forecast), מחפש עיר, בוחר אותה, ואז **מחלׄ את ×Ŗ×•×›×Ÿ דף ×”×Ŗ×—×–×™×Ŗ** ומזין אותו ל-LLM כדי שיענה בעצמו (גישת **RAG**).
2. **שרת ארה"ב (`weather-USA`)** — שולף ×Ŗ×—×–×™×Ŗ והתרעות ×“×Ø×š ה-API ×”×Ø×©×ž×™ של ה-NWS (National Weather Service).

ה-**Host** ×ž×—×‘×Ø את כל ×”×©×Ø×Ŗ×™× ל-LLM (Gemini, ×“×Ø×š ה-API ×”×Ŗ×•××-OpenAI), אוהף מהם ××•×˜×•×ž×˜×™×Ŗ את כל ה-Tools, ×•×ž×Ø×™×„ ×œ×•×œ××Ŗ צ'אט שבה ה-LLM בוחר באיזה כלי ×œ×”×©×Ŗ×ž×© ומפעיל ××•×Ŗ× בזה אחר זה עד ×©×ž×Ŗ×§×‘×œ×Ŗ תשובה.

---

## šŸ—ļø מבנה ×”×¤×Ø×•×™×§×˜

```
project-template/
ā”œā”€ā”€ host.py            # צ'אט ×‘×˜×Ø×ž×™× ×œ ×©×ž×—×‘×Ø את ה-LLM לכל שרתי ה-MCP
ā”œā”€ā”€ client.py          # MCP Client גנרי (×ž×Ŗ×—×‘×Ø לשרת, ×ž×Ø×™×„ Tools)
ā”œā”€ā”€ weather_USA.py     # שרת MCP ×œ××Ø×”"ב — ×“×Ø×š NWS API
ā”œā”€ā”€ weather_Israel.py  # שרת MCP ×œ×™×©×Ø××œ — ×“×Ø×š אטמוט דפדפן (Playwright)
ā”œā”€ā”€ pyproject.toml     # ×Ŗ×œ×•×™×•×Ŗ ×”×¤×Ø×•×™×§×˜
└── README.md
```

### ה-Tools של שרת ×™×©×Ø××œ

| # | Tool | תפקיד |
|---|------|-------|
| 1 | `open_weather_forecast_israel` | פותח דפדפן Chromium ומנווט לאתר ×”×Ŗ×—×–×™×Ŗ |
| 2 | `enter_weather_forecast_city_israel` | מקליד שם עיר בשדה החיפוש |
| 3 | `select_weather_forecast_city_israel` | בוחר את העיר הראשונה ×ž×Ø×©×™×ž×Ŗ ההצעות |
| 4 | `get_weather_forecast_content_israel` | מחלׄ את ×Ŗ×•×›×Ÿ דף ×”×Ŗ×—×–×™×Ŗ (כולל iframes) ×•×ž×—×–×™×Ø אותו ל-LLM |

> šŸ’” ×©×œ×•×©×Ŗ ×”×Ø××©×•× ×™× חולקים אותו דפדפן ×“×Ø×š מצב גלובלי (`_page`), כי כולם ×Ø×¦×™× באותו ×Ŗ×”×œ×™×š-שרת. הרביעי עובר על **כל ה-frames** בדף, כי ×”×Ŗ×—×–×™×Ŗ עצמה נטענת ×‘×Ŗ×•×š `<iframe>` שה-`body` הראשי לא רואה.

---

## āš™ļø ×”×Ŗ×§× ×” והרצה

### דרישות ×ž×§×“×™×ž×•×Ŗ
- Python ≄ 3.13
- [uv](https://docs.astral.sh/uv/) (מנהל ההביבה ×•×”×Ŗ×œ×•×™×•×Ŗ)
- ×ž×¤×Ŗ×— API ל-Gemini ([×§×‘×œ×Ŗ ×ž×¤×Ŗ×— חינמי](https://aistudio.google.com/apikey))

### שלבים

```bash
# 1. ×”×Ŗ×§× ×Ŗ ×”×Ŗ×œ×•×™×•×Ŗ ×•×”×§×ž×Ŗ הביבת העבודה
uv sync

# 2. ×”×Ŗ×§× ×Ŗ דפדפן Chromium עבור Playwright
uv run playwright install chromium
```

### הגדרת ×ž×©×Ŗ× ×™ הביבה

צרו קובׄ `.env` בתיקיית ×”×¤×Ø×•×™×§×˜:

```env
GEMINI_API_KEY=your_api_key_here
GEMINI_MODEL=gemini-2.0-flash
```

### הרצה

```bash
uv run host.py
```

×œ××—×Ø ההפעלה תופיע שורת `Query:` — הקלידו שאלה (או `quit` ליציאה).

---

## šŸ’¬ ×“×•×’×ž××•×Ŗ ×œ×©××œ×•×Ŗ שההוכן יודע ×œ×¢× ×•×Ŗ עליהן

### ×Ŗ×—×–×™×Ŗ ×‘×™×©×Ø××œ (Playwright)
> נפתח חלון דפדפן שבו ×Ø×•××™× את דף ×”×Ŗ×—×–×™×Ŗ, וה-LLM גם עונה בצ'אט.

- "מה ×”×Ŗ×—×–×™×Ŗ ×‘×Ŗ×œ אביב?"
- "כמה ×ž×¢×œ×•×Ŗ צפויות ×ž×—×Ø ×‘×™×Ø×•×©×œ×™×?"
- "איך מזג האוויר בחיפה היום?"
- "תפתחי לי את ×”×Ŗ×—×–×™×Ŗ ×œ×‘××Ø שבע"

### ×Ŗ×—×–×™×Ŗ והתרעות בארה"ב (NWS API)
- "What's the weather forecast for San Francisco?" *(latitude/longitude)*
- "Are there any weather alerts in California?"
- "Show me active weather alerts for NY"

---

## 🧩 איך זה עובד (×Ŗ×Ø×©×™× ×–×Ø×™×ž×”)

```
×ž×©×Ŗ×ž×© → "מה ×”×Ŗ×—×–×™×Ŗ ×‘×Ŗ×œ אביב?"
   │
   ā–¼
 Host  ──►  LLM (Gemini) בוחר Tools להפעיל
   │
   ā–¼  (שרת ×™×©×Ø××œ, בזה אחר זה)
 open → enter("תל אביב") → select → get_content
   │
   ā–¼
 ×Ŗ×•×›×Ÿ ×”×Ŗ×—×–×™×Ŗ חוזר ל-LLM (RAG)
   │
   ā–¼
 LLM כותב תשובה בשפה חופשית בצ'אט ✨
```

---

## šŸ“ הערות

- ה-LLM הוא זה שמחליט אילו Tools להפעיל ובאיזה הדר — לא כתבנו לוגיקה קשיחה.
- שני קבצי שרת = שני ×Ŗ×”×œ×™×›×™× × ×¤×Ø×“×™×, ולכן כל מצב ×ž×©×•×Ŗ×£ (כמו הדפדפן הפתוח) חי ×‘×Ŗ×•×š שרת אחד בלבד.

TDQS

A3.8/5.0

Scored across 4 tools

Disambiguation4/5

Each tool covers a distinct workflow step: opening the page, typing a city, selecting an autocomplete result, and extracting content. The main ambiguity is between open_weather_forecast_israel and get_weather_forecast_content_israel, since both could sound like they return forecast data without reading the descriptions carefully.

Naming Consistency5/5

All tool names follow the same verb-first snake_case pattern and consistently include weather_forecast and israel context. This makes the order and purpose of the tools predictable.

Tool Count5/5

Four tools is appropriate for the narrow browser-automation workflow this server provides. Each tool contributes one essential step, and the set is neither bloated nor too thin.

Completeness4/5

The tool surface covers the full workflow from opening the forecast site to retrieving the forecast text for a chosen city. It lacks fallback or reset tools, but those are not essential for the core task.

Maintenance

ActivitySlowing
ResponsivenessNo issues