Coverage for mcp/resources/demos.py: 90%
35 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-15 15:07 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-15 15:07 +0000
1"""Demo and walkthrough resources (demos:// scheme) for the GCO MCP server."""
3from pathlib import Path
5from server import mcp
7PROJECT_ROOT = Path(__file__).parent.parent.parent
8DEMO_DIR = PROJECT_ROOT / "demo"
9_DEMO_EXTENSIONS = {".md", ".sh", ".py"}
12@mcp.resource("demos://gco/index")
13def demos_index() -> str:
14 """List demo walkthroughs, live demo scripts, and presentation materials."""
15 lines = ["# Demo & Walkthrough Resources\n"]
16 lines.append("## Walkthroughs")
17 for name in ("DEMO_WALKTHROUGH", "INFERENCE_WALKTHROUGH", "LIVE_DEMO"):
18 path = DEMO_DIR / f"{name}.md"
19 if path.is_file(): 19 ↛ 17line 19 didn't jump to line 17 because the condition on line 19 was always true
20 lines.append(f"- `demos://gco/{name}` — {name.replace('_', ' ').title()}")
21 lines.append("\n- `demos://gco/README` — Demo starter kit overview")
22 lines.append("\n## Live Demo Scripts")
23 for name in (
24 "live_demo.sh",
25 "lib_demo.sh",
26 "record_demo.sh",
27 "record_deploy.sh",
28 "record_destroy.sh",
29 ):
30 path = DEMO_DIR / name
31 if path.is_file(): 31 ↛ 23line 31 didn't jump to line 23 because the condition on line 31 was always true
32 lines.append(f"- `demos://gco/{name}` — {name}")
33 lines.append("\n## Utilities")
34 path = DEMO_DIR / "md_to_pdf.py"
35 if path.is_file(): 35 ↛ 37line 35 didn't jump to line 37 because the condition on line 35 was always true
36 lines.append("- `demos://gco/md_to_pdf.py` — Markdown to PDF converter")
37 return "\n".join(lines)
40@mcp.resource("demos://gco/{filename}")
41def demo_resource(filename: str) -> str:
42 """Read a demo walkthrough, script, or utility file."""
43 path = DEMO_DIR / filename
44 if not path.is_file():
45 path = DEMO_DIR / f"{filename}.md"
46 if not path.is_file():
47 available = sorted(
48 f.name for f in DEMO_DIR.iterdir() if f.is_file() and f.suffix in _DEMO_EXTENSIONS
49 )
50 return f"Demo file '{filename}' not found. Available:\n" + "\n".join(available)
51 if path.suffix not in _DEMO_EXTENSIONS: 51 ↛ 52line 51 didn't jump to line 52 because the condition on line 51 was never true
52 return f"File type '{path.suffix}' not served. Allowed: {', '.join(_DEMO_EXTENSIONS)}"
53 return path.read_text()