Coverage for gco_mcp/resources/iam_policies.py: 88.00%

19 statements  

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

1"""IAM policy resources (iam:// scheme) for the GCO MCP server.""" 

2 

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

4from server import mcp 

5 

6IAM_POLICIES_DIR = PROJECT_ROOT / "docs" / "iam-policies" 

7 

8 

9@mcp.resource("iam://gco/policies/index") 

10def iam_policies_index() -> str: 

11 """List available IAM policy templates for GCO access control.""" 

12 lines = ["# IAM Policy Templates\n"] 

13 for f in sorted(IAM_POLICIES_DIR.glob("*.json")): 

14 lines.append(f"- `iam://gco/policies/{f.name}` — {f.stem}") 

15 readme = IAM_POLICIES_DIR / "README.md" 

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

17 lines.append("\n- `iam://gco/policies/README.md` — policy documentation") 

18 return "\n".join(lines) 

19 

20 

21@mcp.resource("iam://gco/policies/{filename}") 

22def iam_policy_resource(filename: str) -> str: 

23 """Read an IAM policy template.""" 

24 path = IAM_POLICIES_DIR / filename 

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

26 available = sorted(f.name for f in IAM_POLICIES_DIR.glob("*") if f.is_file()) 

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

28 return path.read_text()