Pikud Haoref Real-Time Alert System

A comprehensive middleware service and MCP server for accessing Israeli emergency alerts from the official Pikud Haoref (Israeli Home Front Command) API.
Overview
This project provides two ways to access Israeli emergency alert data using a publish-subscribe architecture:
FastAPI Middleware Service - Single source polling with real-time SSE streaming
MCP Server - Event-driven subscriber for AI assistants (built with FastMCP)
The FastAPI service polls the official Pikud Haoref API at https://www.oref.org.il/WarningMessages/alert/alerts.json and publishes alerts via Server-Sent Events. The MCP server subscribes to this stream, creating an efficient pub-sub system that eliminates duplicate API calls while providing real-time access to emergency alerts including rocket alerts, aerial intrusions, earthquakes, and other emergencies.
Features
FastAPI Service Features
Single-source polling of emergency alerts (eliminates duplicate API calls)
Real-time SSE streaming via public webhook endpoint
API key authentication for client endpoints and geo-restriction to Israel
Docker support for easy deployment
Comprehensive testing suite
MCP Server Features
Event-driven SSE client - Subscribes to FastAPI webhook for real-time alerts
3 Tools for AI assistants:
check_current_alerts- Check for active alerts from subscribed streamget_alert_history- Get recent alerts with filtering (limit: 1-50, region filter, intelligent city matching)get_connection_status- Check SSE subscription connection status
2 Resources:
poha://alerts/recent- JSON data of recent alertspoha://alerts/current-status- System status information
Smart City Filtering:
Exact substring matching - Find alerts by city name (e.g., "תל אביב" matches all Tel Aviv areas)
Fuzzy matching - Intelligent matching with threshold 60 for partial/similar names
Multi-city support - Search multiple cities simultaneously
Hebrew city names - Optimized for Hebrew location names from the API
Built with FastMCP following proven patterns
Automatic reconnection and error handling for SSE connections
Quick Start
Option 1: FastAPI Service (Requires API Key)
Install dependencies:
Configure environment (create
.envfile):
Run the service:
Connect to the stream:
Option 2: MCP Server (No API Key Required)
Install dependencies:
Configure your MCP client (Claude Desktop, etc.):
For Claude Desktop, add to ~/Library/Application Support/Claude/claude_desktop_config.json:
Cursor IDE, add to .cursor/mcp.json in your project:
Start the services:
Access URLs after startup:
FastAPI + Swagger UI: http://localhost:8000/docs
MCP Server: http://localhost:8001/mcp
SSE Gateway: http://localhost:8002
Start using - The server will be available as "Pikud Haoref Alert System" in your MCP client via HTTP transport.
API Endpoints (FastAPI Service)
GET /
Basic status endpoint.
GET /api/alerts-stream
Headers: X-API-Key: your-key
Server-Sent Events stream for real-time alerts (authenticated endpoint). Returns:
event: new_alert- When a new alert is detected: keep-alive- Periodic keep-alive messages
GET /api/webhook/alerts
Headers: X-API-Key: your-key
Internal SSE webhook endpoint for services like the MCP server. Streams the same alert data as the client endpoint and requires the same API key authentication for security. Designed for server-to-server communication.
Example response for both endpoints:
MCP Tools Usage
Check Current Alerts
Get Alert History MCP
City Filtering Examples:
cities=["תל אביב"]- Finds all Tel Aviv areas (דרום העיר ויפו, מזרח, מרכז העיר, עבר הירקון)cities=["חיפה"]- Finds all Haifa-related alertscities=["תל אביב", "חיפה", "ירושלים"]- Multiple cities simultaneouslycities=["תל אביב מרכז"]- Fuzzy matches to "תל אביב - מרכז העיר"cities=["all"]- No city filtering (shows all alerts)
Check Connection Status
Architecture
The system uses a publish-subscribe architecture with the following components:
Pikud Haoref API - External data source (government emergency alerts)
FastAPI Middleware - Single source polling + SSE publisher (polls every 2 seconds)
MCP Server - SSE subscriber + tool provider for AI assistants
Client Applications - Web frontends, mobile apps, AI assistants, or other services
Key Benefits:
✅ 50% reduction in API calls (single polling source)
✅ Real-time propagation of alerts via SSE
✅ Event-driven architecture for better scalability
✅ Automatic reconnection for robust SSE connections
Visual Diagram: Run python diagram.py to generate poha_sse_architecture.png showing the complete system architecture.
Security Features
API Key Authentication (Required for All Endpoints)
Important: API key authentication is required for both SSE endpoints for security.
Both SSE endpoints require API key authentication via
X-API-KeyheaderMCP server connects with authentication to the internal webhook endpoint
Same API key used for both client and internal service authentication
Geo-Restriction (Optional)
Configure GEOIP_DB_PATH to restrict access to Israeli IP addresses only:
Sign up at MaxMind
Download
GeoLite2-Country.mmdbSet
GEOIP_DB_PATHin your.envfile
Development
Project Structure
Testing
Local Development (Alternative to Docker)
If you prefer to develop without Docker:
Recommended: Use Docker with make up for easier development.
Dependencies
Core:
fastapi,uvicorn,httpx,python-dotenvSecurity:
geoip2,slowapiMCP:
fastmcp,fuzzywuzzy,python-LevenshteinTesting:
pytest,pytest-asyncio,respx
Docker Deployment
Services Overview
The system runs 3 Docker containers with the following ports:
Service | Container | Port | Description |
FastAPI |
|
| Main API service, alert polling, SSE webhooks |
MCP Server |
|
| Model Context Protocol server for AI assistants |
SSE Gateway |
|
| SSE gateway for VSCode extension |
Access URLs:
FastAPI Swagger: http://localhost:8000/docs
MCP Endpoint: http://localhost:8001/mcp
SSE Gateway: http://localhost:8002
Quick Start with Make
Manual Docker Commands (Alternative)
Data Source
API:
https://www.oref.org.il/WarningMessages/alert/alerts.jsonProvider: Israeli Government (Pikud Haoref - Home Front Command)
Coverage: All emergency alerts in Israel
Update Frequency: Every 2 seconds
Data Types: Rocket alerts, aerial intrusions, earthquakes, emergency announcements
Use Cases
Emergency Response Teams - Real-time alert monitoring
News Organizations - Breaking news automation
Israeli Residents - Personal safety notifications
Researchers - Emergency pattern analysis
AI Assistants - Contextual emergency information
Mobile Apps - Push notification services
Smart Home Systems - Automated responses to alerts
Configuration Examples
FastAPI Service .env File
Troubleshooting
Common Issues
"API key is missing" - Ensure
X-API-Keyheader is set for both client and webhook endpointsMCP connection fails - Check:
Python path in MCP config (use full venv path if needed:
/path/to/venv/bin/python)API_KEY environment variable is set correctly
FastAPI service is running on localhost:8000
Restart your MCP client (Cursor, Claude Desktop, etc.)
Alternative: Use the provided
start_mcp.shscript as the command
Connection timeouts - Check your internet connection and firewall settings
Geo-restriction errors - Verify
GeoLite2-Country.mmdbpath and file permissionsSSE authentication fails - Verify API key matches between FastAPI service and MCP config
City filtering not working -
Use Hebrew city names (e.g., "תל אביב" not "Tel Aviv")
Check exact city names in alert history first:
cities=["all"]Try broader names for fuzzy matching: "תל אביב" instead of "תל אביב - מרכז העיר"
ModuleNotFoundError: No module named 'fuzzywuzzy' -
Rebuild Docker containers:
docker-compose build --no-cacheInstall dependencies:
pip install fuzzywuzzy python-Levenshtein
Logs
Both services provide detailed logging. Check logs for:
API polling status
SSE client connections and authentication
MCP server webhook connection status
Error messages
Security events
Contributing
Fork the repository
Create a feature branch
Add tests for new functionality
Ensure all tests pass
Submit a pull request
License
This project accesses public emergency alert data from the Israeli government. The service is designed for legitimate emergency preparedness and news reporting purposes.
Disclaimer
This service provides access to official Israeli emergency alert data but is not affiliated with or endorsed by the Israeli government or Pikud Haoref. Always follow official emergency procedures and consult official sources for critical safety information.