File size: 2,179 Bytes
b356c3f
23a9367
7b6b271
23a9367
 
 
 
 
 
 
 
 
 
 
 
 
 
b356c3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23a9367
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
MCP Server Configuration for Surf Spot Finder.

This module implements the Model Context Protocol server that exposes
surf spot data as MCP resources. It provides the core resource handlers
for listing and reading surf spot information.

The server exposes:
    - surf://spots/database: 22 world-class surf spots with metadata
    
Example:
    >>> resources = await list_resources()
    >>> content = await read_resource("surf://spots/database")
    >>> spots = json.loads(content)["spots"]
    
Author: Surf Spot Finder Team
License: MIT
"""

import json
from pathlib import Path
from typing import List

# MCP imports
from mcp.server import Server
from mcp.types import Resource

# Initialize MCP server
server = Server("surf-spot-finder")

# Get absolute path to data directory
DATA_DIR = Path(__file__).parent / "data"
SPOTS_FILE = DATA_DIR / "surf_spots.json"


@server.list_resources()
async def list_resources() -> List[Resource]:
    """
    List all available MCP resources.
    
    Returns:
        List of resources that can be read via read_resource()
    """
    return [
        Resource(
            uri="surf://spots/database",
            name="Surf Spots Database",
            description="22 world-class surf spots with optimal conditions and location data",
            mimeType="application/json"
        )
    ]


@server.read_resource()
async def read_resource(uri: str) -> str:
    """
    Read content of an MCP resource.
    
    Args:
        uri: Resource URI (e.g., "surf://spots/database")
    
    Returns:
        Resource content as string
    
    Raises:
        ValueError: If URI is not recognized
        FileNotFoundError: If resource file doesn't exist
    """
    if uri == "surf://spots/database":
        if not SPOTS_FILE.exists():
            raise FileNotFoundError(f"Surf spots database not found at {SPOTS_FILE}")
        
        with open(SPOTS_FILE, 'r', encoding='utf-8') as f:
            content = f.read()
        
        return content
    
    else:
        raise ValueError(f"Unknown resource URI: {uri}")


# Export server instance for use by other modules
__all__ = ['server', 'list_resources', 'read_resource']