get_seismic_data
Retrieve seismic activity data for Portugal from the last 30 days, with options to filter by specific regions including Continental Portugal, Azores, and Madeira.
Instructions
Get seismic activity data for Portugal (Informação sismicidade, últimos 30 dias).
Args:
region: Region to filter ('all', 'continente', 'açores', 'madeira').
Default is 'all' for all regions.
Note: This endpoint returns the last 30 days of seismic information for
Azores Archipelago, Continental Portugal, and Madeira Archipelago.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | all |
Implementation Reference
- weather.py:159-210 (handler)The handler function decorated with @mcp.tool(), which registers and implements the get_seismic_data tool. It fetches seismic data from IPMA API endpoints, handles multiple possible URLs, filters by region if applicable, and formats the response as a string. Input schema defined by type hint region: str = 'all' and detailed docstring.@mcp.tool() async def get_seismic_data(region: str = "all") -> str: """Get seismic activity data for Portugal (Informação sismicidade, últimos 30 dias). Args: region: Region to filter ('all', 'continente', 'açores', 'madeira'). Default is 'all' for all regions. Note: This endpoint returns the last 30 days of seismic information for Azores Archipelago, Continental Portugal, and Madeira Archipelago. """ # Based on API exploration, trying common patterns for seismic data # The exact endpoint might vary, trying multiple possible URLs possible_urls = [ f"{IPMA_API_BASE}/observation/seismic/latest30days.json", f"{IPMA_API_BASE}/seismic-data.json", f"{IPMA_API_BASE}/observation/seismology/events.json" ] seismic_data = None for url in possible_urls: seismic_data = await make_ipma_request(url) if seismic_data: break if not seismic_data: return """Seismic data endpoint is currently unavailable. The IPMA API provides seismic information for the last 30 days covering: - Continental Portugal - Azores Archipelago - Madeira Archipelago Please try again later or check the IPMA website directly.""" # Process and format the seismic data based on actual structure result = f"Seismic Activity (Last 30 Days)\n" result += f"Region Filter: {region}\n\n" # Add data processing logic based on actual API response structure if isinstance(seismic_data, list): filtered_events = seismic_data if region.lower() != "all": # Filter by region if the data structure supports it pass result += f"Total Events: {len(filtered_events)}\n\n" for event in filtered_events[:20]: # Show first 20 events result += f"{event}\n---\n" else: result += str(seismic_data) return result
- weather.py:159-159 (registration)The @mcp.tool() decorator registers the get_seismic_data function as an MCP tool.@mcp.tool()
- weather.py:160-169 (schema)Input schema from type annotation (region: str = 'all') and comprehensive docstring describing parameters, usage, and output format.async def get_seismic_data(region: str = "all") -> str: """Get seismic activity data for Portugal (Informação sismicidade, últimos 30 dias). Args: region: Region to filter ('all', 'continente', 'açores', 'madeira'). Default is 'all' for all regions. Note: This endpoint returns the last 30 days of seismic information for Azores Archipelago, Continental Portugal, and Madeira Archipelago. """
- weather.py:12-20 (helper)Helper function used by get_seismic_data to make HTTP requests to IPMA API endpoints with error handling.async def make_ipma_request(url: str) -> dict[str, Any] | list[dict[str, Any]] | None: """Make a request to the IPMA API with proper error handling.""" async with httpx.AsyncClient() as client: try: response = await client.get(url, timeout=30.0) response.raise_for_status() return response.json() except Exception: return None