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

30 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-09-14 22:07 +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"} 

8 

9 

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

11def demos_index() -> str: 

12 """List demo walkthroughs and live demo scripts.""" 

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(): 

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(): 

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

31 return "\n".join(lines) 

32 

33 

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

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

36 """Read a demo walkthrough or script.""" 

37 path = DEMO_DIR / filename 

38 if not path.is_file(): 

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

40 if not path.is_file(): 

41 available = sorted( 

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

43 ) 

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

45 if path.suffix not in _DEMO_EXTENSIONS: 

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

47 return path.read_text()