Skip to main content
Glama

שרת MCP למזג אוויר בישראל (Playwright & Gemini) 🌦️🤖

מימוש של שרת מבוסס פרוטוקול הקשר למודלים (MCP - Model Context Protocol) המעניק למודל שפה גדול (LLM) יכולות שליטה אוטומטיות בדפדפן (Browser Use). הפרויקט משתמש בספריית Playwright כדי לנונווט, לבצע אינטראקציה ולשלוף נתוני מזג אוויר בזמן אמת מאתר התחזית הישראלי, תוך ביצוע לולאת RAG (Retrieval-Augmented Generation) מלאה ואוטונומית ישירות בתוך הטרמינל.

🎯 מטרות הפרויקט ויעדי למידה

  • ארכיטקטורת MCP: בנייה וחשיפה של כלים (Tools) מותאמים אישית ל-LLM באמצעות ה-SDK הרשמי של Anthropic.

  • אוטומציית דפדפן: שימוש ב-Microsoft Playwright לצורך שליטה תוכנתית בדפדפן Chromium, תוך עקיפת המגבלות של גירוד מידע (Scraping) סטטי רגיל.

  • סוכן RAG מבוסס פעולה (Agentic Flow): מתן אפשרות ל-LLM לנהל בעצמו ובאופן אוטומטי מספר שלבים בדפדפן בזה אחר זה (פתיחה ➔ חימוש ➔ בחירה ➔ חילוץ מידע) ולהשיב למשתמש על בסיס התוכן הדינמי של העמוד.


Related MCP server: MCP Playwright Weather Israel

🧩 ארכיטקטורה ועיצוב טכנולוגי

בניגוד למימושים פשוטים של Scraping, פרויקט זה מבטיח יציבות גבוהה ושמירה על מצב הדפדפן (State) באמצעות:

  1. ניהול State גלובלי בשרת: מופע הדפדפן והעמוד (browser ו-page) מנוהלים כמשתנים גלובליים בתוך הקובץ weather_Israel.py. השרת שומר על דפדפן פעיל אחד לאורך כל סבבי הקריאות של הכלים, במקום לפתוח ולסגור אותו מחדש בכל פעם. הדבר חוסך במשאבים ושומר על הקשר השיחה.

  2. סנכרון חסין (Robust Synchronization): שימוש בזמני המתנה אסינכרוניים מפורשים (wait_for_selector ו-wait_for_load_state("networkidle")) כדי להבטיח שרשימות נפתחות (Dropdown) ומעברי דפים נטענים לחלוטין לפני שהסוכן מנסה ללחוץ או לקרוא מהם, מה שמונע קריסות בשמות ערים מורכבים.

  3. אופטימיזציית טוקנים (RAG נקי): במקום להעביר את כל קוד ה-HTML הגולמי והרועש של העמוד לתוך הקונטקסט של המודל, כלי השליפה מטרגט סלקטורים ספציפיים (CSS Selectors) המכילים את נתוני התחזית בלבד ומסנן רעשי רקע עיצוביים.


🛠️ סטאק טכנולוגי

  • MCP SDK: שכבת הפרוטוקול הרשמית של Anthropic לחיבור הכלים למודל.

  • Playwright: ספריית האוטומציה המודרנית של Microsoft לשליטה בדפדפנים.

  • UV: מנהל החבילות המהיר לפייתון לצורך התקנה וסנכרון סביבת העבודה.

  • Gemini 2.5 Flash: מודל השפה המרכזי המנהל את לולאת קבלת ההחלטות והפעלת הכלים.


🚀 התקנה והרצה

עקבי אחר השלבים הבאים כדי להרים את הסביבה ולהריץ את הפרויקט באופן מקומי:

  1. סנכרון התלויות והפעלת סביבת העבודה:

    uv sync
    התקנת דפדפן כרום (Chromium) עבור Playwright:

Bash uv run playwright install chromium הרצת צ'אט הטרמינל (ה-Client):

Bash uv run host.py 💻 דוגמת שימוש והרצה בזמן אמת לאחר הפעלת ה-Client, ניתן לשוחח עם הסוכן בשפה חופשית בעברית. המודל יחליט בעצמו באילו כלים להשתמש, יבצע את הפעולות בדפדפן הפתוח (הנפתח במצב נראה לעין - headless=False), ויציג את התחזית הסופית בטרמינל.

לוג הרצה מוצלח מהטרמינל (עבור ירושלים): Plaintext Query: מה המזג אוויר בירושלים? Connected to server with tools: ['open_weather_forecast_israel', 'enter_weather_forecast_city_israel', 'select_weather_forecast_city_israel', 'get_page_content_israel']

🤖 גמיני חושב... (סיבוב 1/5) 📞 המודל מפעיל את הכלי: weather_Israel__open_weather_forecast_israel עם הפרמטרים: {}

🤖 גמיני חושב... (סיבוב 2/5) 📞 המודל מפעיל את הכלי: weather_Israel__enter_weather_forecast_city_israel עם הפרמטרים: {'city_name': 'ירושלים'}

🤖 גמיני חושב... (סיבוב 3/5) 📞 המודל מפעיל את הכלי: weather_Israel__select_weather_forecast_city_israel עם הפרמטרים: {}

🤖 גמיני חושב... (סיבוב 4/5) 📞 המודל מפעיל את הכלי: weather_Israel__get_page_content_israel עם הפרמטרים: {}

🤖 גמיני חושב... (סיבוב 5/5)

[Calling tool weather_Israel__open_weather_forecast_israel] [Calling tool weather_Israel__enter_weather_forecast_city_israel] [Calling tool weather_Israel__select_weather_forecast_city_israel] [Calling tool weather_Israel__get_page_content_israel]

הטמפרטורה הנוכחית בירושלים היא 30.2 מעלות צלזיוס.

תחזית להיום: לאחר התפזרות עננות הבוקר, ייעשה בהיר. הטמפרטורות יוסיפו להיות מעט גבוהות מהרגיל לעונה, בעיקר בהרים ובפנים הארץ.

הלילה: מעונן חלקית עד בהיר.

תחזית לימים הקרובים:

  • רביעי: לאחר התפזרות עננות הבוקר, ייעשה נאה. תחול ירידה קלה בטמפרטורות בהרים ובפנים הארץ.

  • חמישי: לאחר התפזרות עננות הבוקר, ייעשה נאה. לא צפוי שינוי ניכר בטמפרטורות.

Available Tools

4 tools
enter_weather_forecast_city_israelB

Enters the specified city name into the search box using JS injection to bypass visibility issues. Input should be a string in Hebrew (e.g., 'ירושלים', 'חיפה').

ParametersJSON Schema
NameRequiredDescriptionDefault
city_nameYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses the use of JS injection to bypass visibility issues, which is a notable behavioral trait. However, with no annotations, more details about side effects or prerequisites would be beneficial.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Extremely concise with two sentences. Each sentence is meaningful and front-loaded with the action and constraint.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of an output schema, return values are not needed. However, the description omits workflow context, such as that the page should be loaded or that this tool is part of a sequence with sibling tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description provides examples of proper input in Hebrew, adding constraint and concrete examples beyond the bare schema. This compensates for the 0% schema description coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it enters a city name into a search box using JS injection. However, it does not differentiate from the sibling tool 'select_weather_forecast_city_israel', which may have a similar purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like 'select_weather_forecast_city_israel' or 'open_weather_forecast_israel'. Lacks context for proper tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_page_content_israelA

Extracts the text content from the loaded weather page for the LLM to read.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Description accurately describes a read operation; no annotations provided but no contradictions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence with essential information, no waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequate for a parameterless tool with output schema; could mention content format but satisfactory.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters, so baseline score applies; description adds no redundant param info.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states it extracts text content from the loaded weather page, distinguishing it from sibling navigation tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implied usage after navigation but no explicit when-to-use or alternative guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

open_weather_forecast_israelA

Opens the weather forecast website for Israel and initializes the browser. This must be called first.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided. Description discloses that it opens a website and initializes the browser, but lacks detail on what initialization entails (e.g., loading data, network requirements, idempotency). Adequate for a simple tool but could be more transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no wasted words. First sentence states action, second gives usage order. Perfectly concise and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given zero parameters and low complexity, the description sufficiently explains the tool's role. Output schema exists but is not described, which is acceptable. Could mention prerequisites or effects, but adequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters exist, and schema coverage is 100%. Baseline for 0 params is 4. Description adds no parameter info as none are needed.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states it opens the weather forecast website for Israel and initializes the browser. The verb 'opens' and resource are specific. Siblings are subsequent actions, distinguishing this as the first step.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states 'This must be called first,' providing clear ordering. No exclusion criteria mentioned, but context implies it is the initial action before siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

select_weather_forecast_city_israelA

Selects the city from the autocomplete dropdown, or presses Enter as a fallback.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description fully discloses the key behavioral traits: it selects from dropdown or falls back to pressing Enter. It does not detail behavior with multiple matches or failure cases, but for a simple UI action it is transparent enough.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence of 14 words conveys all necessary information with no redundancy. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no parameters and an output schema present, the description sufficiently explains the tool's action. It covers the primary behavior and fallback, making it complete for an agent to use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters are defined, and schema coverage is 100% (since none exist). Baseline score of 4 applies as the description does not need to add parameter info.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states it selects the city from an autocomplete dropdown, with a fallback to pressing Enter. Verb 'Selects' and resource 'city from autocomplete dropdown' are specific, and the description distinguishes from sibling 'enter_weather_forecast_city_israel' (which likely types the city).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides context on when to use the fallback (press Enter if dropdown not present), implying the tool is used after typing a city name. However, it does not explicitly compare to alternatives or state when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv0.1.0
    • First observedenter_weather_forecast_city_israel
    • First observedget_page_content_israel
    • First observedopen_weather_forecast_israel
    • First observedselect_weather_forecast_city_israel

TDQS

A3.9/5.0

Scored across 4 tools

Disambiguation4/5

Each tool has a distinct role in the workflow: opening the site, entering city, selecting from dropdown, and retrieving content. Only potential confusion is between enter and select, but descriptions clarify they are different steps.

Naming Consistency3/5

Tool names use a mix of patterns: 'open_weather_forecast_israel' lacks 'city', while others include 'city' or 'page_content'. The verb prefixes are consistent, but the descriptive suffixes vary.

Tool Count5/5

Four tools are well-scoped for the task of retrieving a weather forecast for an Israeli city. Each tool is necessary and none are superfluous.

Completeness4/5

The tools cover the essential steps of the weather retrieval workflow. A minor gap might be the absence of error handling or city validation, but the surface is complete for basic usage.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers