Coverage for gco_mcp/resources/demos.py: 90.00%

34 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-30 21:22 +0000

1"""Demo and walkthrough resources (demos:// scheme) for the GCO MCP server.""" 

2 

3from cli_runner import PROJECT_ROOT # runtime-resolved checkout root (uvx-safe) 

4from server import mcp 

5 

6DEMO_DIR = PROJECT_ROOT / "demo" 

7_DEMO_EXTENSIONS = {".md", ".sh", ".py"} 

8 

9 

10@mcp.resource("demos://gco/index") 

11def demos_index() -> str: 

12 """List demo walkthroughs, live demo scripts, and presentation materials.""" 

13 lines = ["# Demo & Walkthrough Resources\n"] 

14 lines.append("## Walkthroughs") 

15 for name in ("DEMO_WALKTHROUGH", "INFERENCE_WALKTHROUGH", "LIVE_DEMO"): 

16 path = DEMO_DIR / f"{name}.md" 

17 if path.is_file(): 17 ↛ 15line 17 didn't jump to line 15 because the condition on line 17 was always true

18 lines.append(f"- `demos://gco/{name}` — {name.replace('_', ' ').title()}") 

19 lines.append("\n- `demos://gco/README` — Demo starter kit overview") 

20 lines.append("\n## Live Demo Scripts") 

21 for name in ( 

22 "live_demo.sh", 

23 "lib_demo.sh", 

24 "record_demo.sh", 

25 "record_deploy.sh", 

26 "record_destroy.sh", 

27 ): 

28 path = DEMO_DIR / name 

29 if path.is_file(): 29 ↛ 21line 29 didn't jump to line 21 because the condition on line 29 was always true

30 lines.append(f"- `demos://gco/{name}` — {name}") 

31 lines.append("\n## Utilities") 

32 path = DEMO_DIR / "md_to_pdf.py" 

33 if path.is_file(): 33 ↛ 35line 33 didn't jump to line 35 because the condition on line 33 was always true

34 lines.append("- `demos://gco/md_to_pdf.py` — Markdown to PDF converter") 

35 return "\n".join(lines) 

36 

37 

38@mcp.resource("demos://gco/{filename}") 

39def demo_resource(filename: str) -> str: 

40 """Read a demo walkthrough, script, or utility file.""" 

41 path = DEMO_DIR / filename 

42 if not path.is_file(): 

43 path = DEMO_DIR / f"{filename}.md" 

44 if not path.is_file(): 

45 available = sorted( 

46 f.name for f in DEMO_DIR.iterdir() if f.is_file() and f.suffix in _DEMO_EXTENSIONS 

47 ) 

48 return f"Demo file '{filename}' not found. Available:\n" + "\n".join(available) 

49 if path.suffix not in _DEMO_EXTENSIONS: 49 ↛ 50line 49 didn't jump to line 50 because the condition on line 49 was never true

50 return f"File type '{path.suffix}' not served. Allowed: {', '.join(_DEMO_EXTENSIONS)}" 

51 return path.read_text()