MalkaBruk-MCPProject
An MCP server that provides weather forecasts and alerts for the USA and Israel, using the National Weather Service API and Playwright-based browser automation.
README
MCP Weather Forecast Project
๐ Project Overview
This project demonstrates a complete Model Context Protocol (MCP) Server implementation with Playwright-based browser automation. It enables Claude AI to fetch real-time weather forecasts from Israeli and USA weather websites by automating browser interactions without manual intervention.
The project implements two MCP servers:
- weather_USA.py - Fetches USA weather alerts and forecasts from the National Weather Service API
- weather_Israel.py - Automates browser interactions with the Israel Weather 2 Day website using Playwright
๐ฏ Learning Objectives
By working through this project, you will understand:
- โ How to implement your own MCP Server for custom needs
- โ How to use Playwright to add browser control capabilities to LLMs
- โ How to manage browser automation sessions across multiple tool calls
- โ How to create an orchestrator that manages multiple MCP clients
- โ How to integrate Claude AI with custom tools
๐ ๏ธ Technology Stack
- MCP SDK: Anthropic's official library for exposing tools to LLMs
- Playwright: Microsoft's browser automation library for reliable browser control
- FastMCP: Decorator-based framework for building MCP servers quickly
- Cohere API: Cohere's advanced LLM for intelligent tool selection and execution
- Python 3.13+: Async-first Python implementation
๐ฆ Installation
Prerequisites
- Python 3.13 or higher
- Pip or Uv package manager
Setup Steps
- Clone or navigate to the project directory:
cd MCPProject
- Install dependencies:
uv sync
Or with pip:
pip install -r requirements.txt
- Set up environment variables:
Create a
.envfile in the project root:
COHERE_API_KEY=your-cohere-api-key-here
You can get a Cohere API key from cohere.com
- Install Playwright browsers:
playwright install
๐ How to Run
Running the Interactive Chat Host
uv run host.py
The host will:
- Connect to both MCP servers (USA and Israel weather)
- Display available tools
- Start an interactive chat loop
- Allow you to ask questions about weather forecasts
Type your weather-related questions and press Enter. Type quit to exit.
๐ฌ Example Questions and Answers
For USA Weather:
Query: What are the active weather alerts in California?
[System connects to weather_USA MCP and calls get_alerts_in_USA tool]
Response: [Weather alerts for California displayed]
Query: What's the forecast for latitude 40.7128 and longitude -74.0060 (New York)?
[System calls get_forecast_in_USA tool with coordinates]
Response: [5-day forecast for NYC]
For Israel Weather:
Query: Tell me the weather forecast for Tel Aviv
[System performs the following steps]
1. Opens browser with open_weather_forecast_israel()
2. Enters "Tel Aviv" with enter_weather_forecast_city_israel("Tel Aviv")
3. Selects first city option with select_weather_forecast_city_israel()
4. Extracts forecast with extract_weather_forecast_israel()
Response: [Current weather and forecast for Tel Aviv]
Query: What's the weather like in Jerusalem?
[Same process as above, but for Jerusalem]
Response: [Weather forecast for Jerusalem]
๐ Architecture
System Components
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ host.py (ChatHost) โ
โ - Orchestrates multiple MCP clients โ
โ - Manages tool discovery and execution โ
โ - Handles Claude AI interaction โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ weather_USA.py โ โ weather_Israel.py โ
โ (MCP Server) โ โ (MCP Server) โ
โ โ โ โ
โ Tools: โ โ Tools: โ
โ โข get_alerts_in_USA โ โ โข open_browser โ
โ โข get_forecast_USA โ โ โข enter_city โ
โ โ โ โข select_city โ
โ โ โ โข extract_forecast โ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
โ NWS API โ โ Chromium Browser โ
โ (weather.gov) โ โ (Playwright) โ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
Tool Execution Flow
- User Query โ ChatHost
- Tool Discovery โ List available tools from all MCP servers
- Cohere Analysis โ Cohere AI determines which tools to use
- Tool Execution โ Execute tools in sequence with results
- Response Loop โ If more tools needed, repeat; otherwise return final answer
๐ง Implementation Details
weather_USA.py - API-Based Approach
- Uses the National Weather Service API
- No browser automation needed
- Direct HTTP requests to fetch structured data
- Tools:
get_alerts_in_USA(state)- Fetches active alerts for a US stateget_forecast_in_USA(latitude, longitude)- Gets 5-day forecast for coordinates
weather_Israel.py - Browser Automation Approach
- Uses Playwright for browser control
- Automates the weather2day.co.il website
- Maintains browser session across tool calls
- Tools:
open_weather_forecast_israel()- Opens browser and navigates to websiteenter_weather_forecast_city_israel(city_name)- Types city name in search fieldselect_weather_forecast_city_israel()- Clicks first matching city from dropdownextract_weather_forecast_israel()- Extracts and cleans forecast data from page
Key Implementation Features
Browser Session Management:
# Global browser/page instances to keep browser open
_browser: Browser | None = None
_page: Page | None = None
async def ensure_browser_initialized():
"""Initialize browser if not already done"""
# Browser persists across tool calls
Tool Definition with FastMCP:
@mcp.tool()
async def tool_name(param1: str) -> str:
"""Tool description for Claude"""
# Implementation
MCP Client Integration:
- Each MCP server runs as a subprocess
- Host communicates via stdio (MCP protocol)
- Tools are prefixed with server name to avoid conflicts
๐ Project Structure
MCPProject/
โโโ host.py # Main orchestrator
โโโ client.py # MCP client implementation
โโโ weather_USA.py # USA weather MCP server
โโโ weather_Israel.py # Israel weather MCP server
โโโ pyproject.toml # Project dependencies
โโโ python-version.txt # Required Python version
โโโ README.md # This file
๐ Understanding MCP Tools
Tool Definition
Each tool is a Python async function decorated with @mcp.tool():
@mcp.tool()
async def my_tool(param: str) -> str:
"""
Detailed description of what the tool does.
This docstring is sent to Cohere to help it understand when to use this tool.
Args:
param: Parameter description
Returns:
str: Description of return value
"""
# Implementation
return result
Tool Discovery
When the host connects to an MCP server, it:
- Sends a
list_tools()request - Receives tool metadata (name, description, input schema)
- Registers tools with namespace:
{server_name}__{tool_name} - Sends full tool list to Claude
Tool Execution
When Cohere calls a tool:
- Host receives the tool name and arguments
- Maps to original tool name and MCP client
- Calls the tool on the specific MCP server
- Receives result and provides to Cohere
- Cohere uses result for next reasoning step
๐งช Testing Individual Tools
You can test tools directly in Python:
import asyncio
from weather_Israel import open_weather_forecast_israel, enter_weather_forecast_city_israel
async def test():
result1 = await open_weather_forecast_israel()
print(result1)
result2 = await enter_weather_forecast_city_israel("Tel Aviv")
print(result2)
asyncio.run(test())
๐ Troubleshooting
Browser Not Opening
- Ensure Playwright browsers are installed:
playwright install - Check if Chromium is blocked by antivirus
- Try adding
headless=Trueto browser launch for background mode
Tool Not Found
- Ensure both weather_*.py files are in the same directory
- Check that MCP servers are starting successfully (look for "Connected to server with tools" messages)
- Verify tool names match exactly
Timeout Issues
- Increase the timeout in Playwright selectors
- Check if the website structure has changed
- Add wait conditions for specific elements
SSL/Certificate Issues
The code handles Netfree networks with SSL verification disabled. For production, remove verify=False from httpx configuration.
๐ Extension Ideas
- Add more weather sources - Create additional MCP servers for different weather APIs
- Caching layer - Store forecast data to avoid repeated browser automation
- Notification system - Alert when severe weather is forecasted
- Multi-language support - Handle queries in Hebrew and English
- Historical data - Compare current forecast with historical weather patterns
- GUI Dashboard - Create a web interface showing forecasts from all sources
๐ Resources
๐ค Contributing
To add new weather sources:
- Create a new
weather_*.pyfile with MCP server implementation - Add MCPClient entry in
host.py - Test with sample queries
- Document tools in README
๐ License
This project is for educational purposes.
Happy weather 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.