"""Learning Resource Finder: fictional catalog, no network or credentials."""
from typing import Annotated
from pydantic import Field
from mcp.server.fastmcp import FastMCP
from mcp.types import ToolAnnotations

mcp = FastMCP("Learning Resource Finder")
CATALOG = [
    {"id": "py-loops", "title": "Python loops", "minutes": 15, "format": "exercise"},
    {"id": "py-functions", "title": "Python functions", "minutes": 25, "format": "lab"},
    {"id": "html-forms", "title": "HTML forms", "minutes": 20, "format": "lab"},
    {"id": "mcp-contracts", "title": "MCP tool contracts", "minutes": 40, "format": "project"},
]

@mcp.tool(annotations=ToolAnnotations(readOnlyHint=True))
def find_resources(
    topic: Annotated[str, Field(strict=True, min_length=1, max_length=80)],
    max_minutes: Annotated[int, Field(strict=True, ge=1, le=120)] = 30,
) -> dict[str, object]:
    """Find fictional learning resources by title and time limit. Never enrolls anyone."""
    query = topic.strip().casefold()
    if not query:
        raise ValueError("Enter a topic containing a non-space character.")
    matches = [item for item in CATALOG
               if query in item["title"].casefold() and item["minutes"] <= max_minutes]
    return {"demo": True, "count": len(matches), "resources": matches}

if __name__ == "__main__":
    mcp.run(transport="stdio")
