D3MI4N's picture
docs: update README with new repository structure
5796406

A newer version of the Gradio SDK is available: 6.1.0

Upgrade
metadata
title: Surf Spot Finder โ€” AI-Powered MCP Agent
emoji: ๐Ÿ„โ€โ™‚๏ธ
colorFrom: blue
colorTo: indigo
sdk: gradio
sdk_version: 5.49.1
app_file: hf_space/app.py
pinned: false
license: mit
tags:
  - mcp-in-action-track-customer
  - building-mcp-track-consumer
short_description: AI surf agent with autonomous reasoning using MCP protocol

๐Ÿ„โ€โ™‚๏ธ Surf Spot Finder - AI Agent (MCP in Action)

AI-powered surf spot recommendations with autonomous reasoning and real-time conditions

This project demonstrates MCP in Action with an intelligent agent that autonomously analyzes surf conditions, reasons about optimal spots, and provides natural language explanations of its decision-making process.

๐ŸŽฌ Demo Video

Watch the Demo Video to see how the MCP server works in action.

๐Ÿค– Agent Capabilities

  • ๐Ÿง  Autonomous Reasoning: AI agent analyzes wave conditions and makes intelligent recommendations
  • ๐ŸŒŠ Real-time Conditions: Live wave data from Stormglass API
  • ๐Ÿ“ Location Intelligence: Geocoding and distance-based filtering
  • ๐ŸŽฏ Multi-factor Scoring: Sophisticated evaluation (waves, wind, swell, skill compatibility)
  • ๐Ÿ’ฌ Natural Language: LLM-powered explanations and insights
  • ๐Ÿ›ก๏ธ Safety-focused: Skill-level appropriate recommendations

๐Ÿ”ง MCP Resources Implementation

Surf spots are exposed as MCP resources following the Model Context Protocol.

Resource

  • URI: surf://spots/database
  • Content: 22 world-class surf spots with metadata
  • Format: JSON

Server Implementation (mcp_server/mcp_server.py)

@server.list_resources()
async def list_resources():
    return [Resource(uri="surf://spots/database", name="Surf Spots Database", ...)]

@server.read_resource()
async def read_resource(uri: str):
    # Returns surf_spots.json content

Client Usage (tools/spot_finder_tool.py)

  • Primary: MCP resource access via read_resource()
  • Fallback: File I/O for async context compatibility

Testing MCP Resources

python tests/test_mcp_resources.py
# Expected output:
# โœ… Found 1 resource(s)  
# โœ… Loaded 22 surf spots
# ๐ŸŽ‰ All tests passed!

๐Ÿ—๏ธ MCP Architecture

MCP Server (mcp_server/)

Tools Available:

  • find_surf_spots - Main orchestration tool with AI reasoning
  • surf_llm_agent - LLM-powered analysis and explanations
  • get_wave_data - Real-time conditions from Stormglass
  • resolve_location - Geocoding and coordinate resolution
  • calculate_distance - Distance calculations

HF Space Consumer (hf_space/)

  • Gradio Interface: User-friendly web UI
  • MCP Client: Communicates with MCP server
  • Real-time Demo: Live surf recommendations

๐Ÿš€ Quick Start

Local Development

# Clone repository
git clone <repo-url>
cd surf-spot-finder-mcp

# Install dependencies
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

# Set API keys (optional - works with fallback)
export STORMGLASS_API_KEY=your_key
export OPENAI_API_KEY=your_key  # For enhanced LLM reasoning

# Quick demo
python scripts/run_local_demo.py

๐ŸŒŠ How It Works

  1. User Input: Location + preferences (skill level, board type)
  2. Location Resolution: Convert address to coordinates
  3. Spot Discovery: Find nearby surf spots from curated database
  4. Condition Analysis: Get real-time wave data via Stormglass
  5. AI Evaluation: Sophisticated scoring algorithm + LLM reasoning
  6. Intelligent Ranking: Sort by compatibility with user preferences
  7. Natural Language Output: AI-generated explanations and insights

๐Ÿ“Š Evaluation Algorithm

Real-Time Data Sources (Automatic Priority):

  • ๐Ÿฅ‡ Stormglass API โ†’ ๐Ÿฅˆ Open-Meteo (free fallback)
  • ๐Ÿฅ‡ OpenAI โ†’ ๐Ÿฅˆ Anthropic โ†’ ๐Ÿฅ‰ OpenRouter โ†’ ๐Ÿ”„ Rule-based

Multi-Factor Scoring System (0-100 scale):

  1. Wave Conditions (35%):

    • Optimal range matching (spot preferences vs. current height)
    • Skill-level safety adjustments (beginners capped at 2m)
    • Progressive scoring curve with diminishing returns
  2. Wind Analysis (25%):

    • Speed compatibility (offshore preferred, onshore penalized)
    • Direction optimization (side-offshore = ideal)
    • Thermal wind pattern recognition
  3. Swell Direction (25%):

    • Angular matching to spot's optimal swell window
    • Bathymetry considerations for wave refraction
    • Seasonal swell pattern analysis
  4. Skill Compatibility (15%):

    • Break type vs. experience level
    • Hazard assessment (rocks, currents, crowds)
    • Progression opportunity scoring

AI Reasoning Layer:

  • Autonomous pattern recognition across multiple conditions
  • Natural language explanations of decision-making process
  • Local knowledge integration and safety recommendations
  • Session timing optimization with weather forecasting

๐Ÿ—บ๏ธ Surf Spot Database

Demo Dataset (Current Implementation)

22 World-Class Spots carefully selected for demonstration:

๐Ÿ‡ช๐Ÿ‡ธ Spain (8 spots)

  • Tarifa, El Palmar, La Barrosa, Sotogrande, Barbate, Cabo Trafalgar, Marbella, Mundaka

๐Ÿ‡บ๐Ÿ‡ธ California, USA (4 spots)

  • Malibu - Surfrider Beach, Venice Beach, Manhattan Beach, Redondo Beach

๐Ÿ‡ต๐Ÿ‡น Portugal (4 spots)

  • Ericeira - Ribeira d'Ilhas, Carcavelos, Guincho, Peniche - Supertubos

๐ŸŒ International (6 spots)

  • Hossegor (France), Pipeline (Hawaii), Bells Beach (Australia), Supertubes (South Africa)

Production Scaling Architecture

Current: JSON File (mcp_server/data/surf_spots.json)

  • โœ… Perfect for demo and development
  • โœ… Easy to understand and modify
  • โœ… No external dependencies

Production Deployment Options:

  • PostgreSQL/PostGIS: Geospatial queries and advanced filtering
  • MongoDB: Flexible schema for evolving spot characteristics
  • Redis Cache: Fast lookup with geographic indexing
  • API Integration: Real-time spot data from surf databases

Scalability Path:

JSON (22 spots) โ†’ Database (1000s spots) โ†’ API Federation (global coverage)

The current JSON approach demonstrates the algorithm and architecture while keeping the demo accessible and maintainable for hackathon evaluation.

๐Ÿงช Testing

Run Tests

# Test MCP resources
python tests/test_mcp_resources.py

# Test complete workflow
python tests/test_workflow.py

# Run unit tests (if pytest installed)
cd mcp_server
pytest tests/

Test Dependencies

The project includes comprehensive tests for:

  • MCP Resources: Resource listing and reading
  • MCP Tools: Individual tool functionality
  • LLM Integration: AI reasoning components
  • API Integration: External service connections

๐Ÿ”ง Configuration

API Keys (All Optional - Intelligent Fallbacks Included):

Wave Data Sources:

  • STORMGLASS_API_KEY: Premium marine data โ†’ Falls back to Open-Meteo (free)

AI Reasoning Providers (Priority Order):

  • OPENAI_API_KEY: GPT-4 analysis (1st choice)
  • ANTHROPIC_API_KEY: Claude reasoning (2nd choice)
  • OPENROUTER_API_KEY: Multi-model access (3rd choice)
  • No API key: Rule-based analysis (always works)

๐ŸŽฏ MCP Hackathon Submission

Track: MCP in Action - Customer
Category: Demonstrates autonomous AI agent behavior

Key Features for Judging:

  • โœ… Agent Reasoning: LLM-powered autonomous decision making
  • โœ… Real-world Impact: Practical surf recommendations with safety focus
  • โœ… MCP Protocol: Proper resource and tool architecture
  • โœ… User Experience: Intuitive Gradio interface
  • โœ… Documentation: Comprehensive setup and usage docs

๐Ÿ† Innovation Highlights

  1. Autonomous Agent Behavior: AI reasons about conditions and explains decisions
  2. Multi-modal Intelligence: Combines real-time data, spatial analysis, and LLM reasoning
  3. MCP Resources: Proper implementation of Model Context Protocol primitives
  4. Safety-first Approach: Skill-level appropriate recommendations prevent dangerous situations
  5. Flexible Architecture: Direct mode with intelligent fallbacks for reliability

๐Ÿ“ Project Structure

surf-spot-finder-mcp/
โ”œโ”€โ”€ mcp_server/                    # MCP Server Implementation
โ”‚   โ”œโ”€โ”€ mcp_server.py             # MCP resource handlers (list_resources, read_resource)
โ”‚   โ”œโ”€โ”€ tools/                    # MCP Tools
โ”‚   โ”‚   โ”œโ”€โ”€ spot_finder_tool.py  # Main orchestration (uses MCP resources)
โ”‚   โ”‚   โ”œโ”€โ”€ llm_agent_tool.py    # AI reasoning & analysis
โ”‚   โ”‚   โ”œโ”€โ”€ surf_eval_tool.py    # Multi-factor scoring algorithm
โ”‚   โ”‚   โ”œโ”€โ”€ stormglass_tool.py   # Wave data API integration
โ”‚   โ”‚   โ”œโ”€โ”€ location_tool.py     # Geocoding & coordinates
โ”‚   โ”‚   โ””โ”€โ”€ marine_data_tool.py  # Fallback weather data
โ”‚   โ”œโ”€โ”€ data/                    # Surf spots database
โ”‚   โ”‚   โ””โ”€โ”€ surf_spots.json      # 22 world-class surf spots (exposed via MCP)
โ”‚   โ”œโ”€โ”€ utils/                   # Utility functions
โ”‚   โ””โ”€โ”€ tests/                   # Unit & integration tests
โ”‚
โ”œโ”€โ”€ hf_space/                     # Gradio UI
โ”‚   โ”œโ”€โ”€ app.py                   # Main interface with enhanced UX
โ”‚   โ”œโ”€โ”€ mcp_client.py            # Direct Mode client
โ”‚   โ””โ”€โ”€ requirements.txt         # HF Space dependencies
โ”‚
โ”œโ”€โ”€ scripts/                      # Utility scripts
โ”‚   โ”œโ”€โ”€ run_local_demo.py        # Quick demo launcher
โ”‚   โ””โ”€โ”€ print_tree.py            # Repository structure visualization
โ”‚
โ”œโ”€โ”€ tests/                        # Root-level integration tests
โ”‚   โ”œโ”€โ”€ test_mcp_resources.py    # MCP resources validation
โ”‚   โ””โ”€โ”€ test_workflow.py         # End-to-end workflow testing
โ”‚
โ”œโ”€โ”€ requirements.txt              # Project dependencies
โ””โ”€โ”€ README.md                     # This documentation

๐Ÿค Contributing

Built for the Hugging Face MCP Hackathon. Contributions welcome!

๐Ÿ“„ License

MIT License - See LICENSE file for details.


๐Ÿ„โ€โ™‚๏ธ Find your perfect wave with AI-powered intelligence!

๐Ÿ”ฎ Future Enhancements

  • Modal Serverless Deployment: Planned for production-scale deployment
  • Global Spot Database: Integration with surf databases for worldwide coverage
  • Forecast Integration: Multi-day weather predictions and session planning
  • Community Features: User ratings, photos, and local tips