D3MI4N's picture
docs: add comprehensive docstrings to all Python files
23a9367
"""
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']