Coverage for gco_mcp/resources/scripts.py: 92.11%

26 statements  

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

1"""Utility script resources (scripts:// scheme) for the GCO MCP server.""" 

2 

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

4from server import mcp 

5 

6SCRIPTS_DIR = PROJECT_ROOT / "scripts" 

7_SCRIPT_EXTENSIONS = {".py", ".sh"} 

8 

9 

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

11def scripts_index() -> str: 

12 """List utility scripts for cluster access, versioning, testing, and operations.""" 

13 lines = ["# Utility Scripts\n"] 

14 readme = SCRIPTS_DIR / "README.md" 

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

16 lines.append("- `scripts://gco/README` — Scripts overview and usage\n") 

17 for f in sorted(SCRIPTS_DIR.iterdir()): 

18 if f.is_file() and f.suffix in _SCRIPT_EXTENSIONS: 

19 desc = f.stem.replace("_", " ").replace("-", " ").title() 

20 lines.append(f"- `scripts://gco/{f.name}` — {desc}") 

21 return "\n".join(lines) 

22 

23 

24@mcp.resource("scripts://gco/{filename}") 

25def script_resource(filename: str) -> str: 

26 """Read a utility script.""" 

27 path = SCRIPTS_DIR / filename 

28 if not path.is_file(): 

29 path = SCRIPTS_DIR / f"{filename}.md" 

30 if not path.is_file(): 

31 available = sorted( 

32 f.name 

33 for f in SCRIPTS_DIR.iterdir() 

34 if f.is_file() and f.suffix in (_SCRIPT_EXTENSIONS | {".md"}) 

35 ) 

36 return f"Script '{filename}' not found. Available:\n" + "\n".join(available) 

37 if path.suffix not in (_SCRIPT_EXTENSIONS | {".md"}): 37 ↛ 38line 37 didn't jump to line 38 because the condition on line 37 was never true

38 return f"File type '{path.suffix}' not served." 

39 return path.read_text()