Coverage for mcp/resources/scripts.py: 92%
27 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"""Utility script resources (scripts:// scheme) for the GCO MCP server."""
3from pathlib import Path
5from server import mcp
7PROJECT_ROOT = Path(__file__).parent.parent.parent
8SCRIPTS_DIR = PROJECT_ROOT / "scripts"
9_SCRIPT_EXTENSIONS = {".py", ".sh"}
12@mcp.resource("scripts://gco/index")
13def scripts_index() -> str:
14 """List utility scripts for cluster access, versioning, testing, and operations."""
15 lines = ["# Utility Scripts\n"]
16 readme = SCRIPTS_DIR / "README.md"
17 if readme.is_file(): 17 ↛ 19line 17 didn't jump to line 19 because the condition on line 17 was always true
18 lines.append("- `scripts://gco/README` — Scripts overview and usage\n")
19 for f in sorted(SCRIPTS_DIR.iterdir()):
20 if f.is_file() and f.suffix in _SCRIPT_EXTENSIONS:
21 desc = f.stem.replace("_", " ").replace("-", " ").title()
22 lines.append(f"- `scripts://gco/{f.name}` — {desc}")
23 return "\n".join(lines)
26@mcp.resource("scripts://gco/{filename}")
27def script_resource(filename: str) -> str:
28 """Read a utility script."""
29 path = SCRIPTS_DIR / filename
30 if not path.is_file():
31 path = SCRIPTS_DIR / f"{filename}.md"
32 if not path.is_file():
33 available = sorted(
34 f.name
35 for f in SCRIPTS_DIR.iterdir()
36 if f.is_file() and f.suffix in (_SCRIPT_EXTENSIONS | {".md"})
37 )
38 return f"Script '{filename}' not found. Available:\n" + "\n".join(available)
39 if path.suffix not in (_SCRIPT_EXTENSIONS | {".md"}): 39 ↛ 40line 39 didn't jump to line 40 because the condition on line 39 was never true
40 return f"File type '{path.suffix}' not served."
41 return path.read_text()