WeatherForcast-MCP-using-playwright

WeatherForcast-MCP-using-playwright

Enables fetching weather forecasts for the USA via NWS API and for Israel via browser automation using Playwright.

Category
访问服务器

README

Weather Forecast MCP Portfolio Project

This project is an advanced portfolio piece that demonstrates a professional-grade workflow for integrating LLMs with custom MCP servers and browser automation.

It showcases how to build a multi-agent system in Python that uses:

  • Anthropic MCP SDK for exposing custom tools to a language model.
  • Playwright for automated browser control and web interaction.
  • Groq for LLM orchestration and tool selection.

Project Overview

The solution includes three main components:

  • host.py — the chat host that connects to multiple MCP clients, discovers available tools, and forwards user requests to the LLM.
  • client.py — a generic MCP client wrapper that launches MCP server scripts and manages STDIO communication.
  • weather_USA.py — a classic MCP server that fetches weather data from the NWS API for the USA.
  • weather_Israel.py — a new MCP server that performs browser automation to retrieve Israeli weather forecast data from a website.

The architecture intentionally separates concerns: one MCP handles API-based weather data, while another MCP handles browser-driven Israeli weather retrieval.


Why this project is portfolio-worthy

This project is designed to reflect both technical depth and learning progress:

  • Building a custom MCP Server from scratch.
  • Integrating browser automation with an LLM workflow.
  • Enabling the model to choose and orchestrate tools dynamically.
  • Solving a real-world problem with non-conventional data access.

It demonstrates the ability to design and implement advanced AI tooling, not just consume existing APIs.


Learning Goals

This project highlights the key professional and educational outcomes:

  • Build an independent MCP Server that exposes custom tools to an LLM.
  • Use Playwright to extend the LLM with browser automation capabilities.
  • Design a multi-step flow that answers real user queries through tool orchestration.
  • Apply RAG-style contextual enrichment by extracting and using page content.

Technical Stack

  • MCP SDK — Anthropic's official toolkit for defining the MCP protocol and exposing tools to the model.
  • Playwright — Microsoft's modern browser automation framework, used here to automate a real website and perform human-like interactions.

Project Requirements

The main goal is to build a new MCP Server that handles Israeli weather forecast requests by opening a browser and navigating to a specific site, rather than using a conventional API.

Recruiter-worthy highlights:

  • A custom MCP Server focused on browser-based data retrieval.
  • Playwright-driven automation for searching and selecting a city in a live website.
  • A multi-step tool chain that simulates manual browsing from within an AI agent.
  • Page extraction and contextualization for the LLM.

Development Stages

Stage 0 — Project Structure

project-template/
├── client.py          # generic MCP Client
├── host.py            # terminal chat host that ties everything together
├── weather_USA.py     # MCP Server for USA using API
└── weather_Israel.py  # ← your core Israel-focused MCP

Stage A — Implement Tools with Playwright

Goal: implement MCP tools that allow the LLM to fetch Israeli weather forecast directly from the browser.

The new MCP should load the forecast page from: https://www.weather2day.co.il/forecast

The MCP exposes three Playwright-based tools that automate the complete flow:

  1. open_weather_forecast_israel — open the browser and navigate to the weather page.
  2. enter_weather_forecast_city_israel — enter the city name into the search field.
  3. select_weather_forecast_city_israel — select the first city suggestion from the list.

To make this work professionally:

  • define each function as an MCP tool using the decorator.
  • add the new MCP to the host's MCP client list.
  • run the system and verify the host selects the new MCP and executes the functions sequentially.

Example command:

uv run host.py

Then ask the system for a forecast in a given city and confirm that the host opened the forecast page in the browser.


Stage B — Let the LLM Finish the Answer

Goal: move beyond tool execution and give the LLM page content so it can answer directly in chat.

Add another tool that extracts the page content, cleans it, and returns a useful context snippet for the LLM. This is the RAG-style enhancement: the model receives actual page text and can incorporate it into the response.


How it works

  1. host.py connects to the MCP clients defined in client.py.
  2. It asks Groq to decide which tool should run for a given user query.
  3. The selected MCP tool runs and returns real data.
  4. If the browser-based MCP is used, Playwright drives the website and extracts context from the page.
  5. The result is returned to the user as a fully formed chat answer.

Why this project matters for AI recruiting

This project shows that I can:

  • architect multi-agent systems.
  • implement custom MCP tools for business logic.
  • use browser automation to access data behind interactive websites.
  • enrich LLM responses with real-world context.
  • solve engineering problems that involve both AI and automation.

Run Instructions

  1. Install dependencies:
python -m pip install -U pip
python -m pip install groq>=0.4.0 mcp>=1.27.0 python-dotenv>=1.2.2 playwright>=1.44.0
python -m playwright install
  1. Create a .env file with:
GROQ_API_KEY=your_groq_api_key_here
GROQ_MODEL=mixtral-8x7b-32768
  1. Run the host:
python host.py
  1. Ask a query about weather forecast in Israel or the USA.

Sample Questions

  • What is the weather forecast for Jerusalem today?
  • Open the Israeli weather site and get the forecast for Tel Aviv.
  • Are there any weather alerts in California?
  • Use the Israel browser tool and answer from the page content.
  • How do I get a 5-day forecast for a US location?

Notes

  • The Israeli MCP is intentionally browser-driven rather than API-driven.
  • The project emphasizes autonomous tool orchestration and dynamic LLM-driven execution.
  • This is a strong portfolio example for AI engineering, agent design, and browser automation skills.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选