Coverage for gco_mcp/resources/infra.py: 93.10%

44 statements  

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

1"""Infrastructure config resources (infra:// scheme) for the GCO MCP server.""" 

2 

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

4from server import mcp 

5 

6DOCKERFILES_DIR = PROJECT_ROOT / "dockerfiles" 

7HELM_CHARTS_FILE = PROJECT_ROOT / "lambda" / "helm-installer" / "charts.yaml" 

8 

9 

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

11def infra_index() -> str: 

12 """List infrastructure configuration files — Dockerfiles, Helm charts, CI/CD.""" 

13 lines = ["# Infrastructure Configuration\n"] 

14 lines.append("## Dockerfiles") 

15 readme = DOCKERFILES_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("- `infra://gco/dockerfiles/README.md` — Dockerfiles overview") 

18 for f in sorted(DOCKERFILES_DIR.iterdir()): 

19 if f.is_file() and not f.name.startswith(".") and f.name != "README.md": 

20 lines.append(f"- `infra://gco/dockerfiles/{f.name}`") 

21 lines.append("\n## Helm Charts") 

22 if HELM_CHARTS_FILE.is_file(): 22 ↛ 24line 22 didn't jump to line 24 because the condition on line 22 was always true

23 lines.append("- `infra://gco/helm/charts.yaml` — Helm chart versions and config") 

24 lines.append("\n## CI/CD") 

25 lines.append("- `ci://gco/index` — GitHub Actions workflows, composite actions, scripts") 

26 lines.append("- `source://gco/config/.gitlab-ci.yml` — GitLab CI pipeline (frozen reference)") 

27 lines.append("- `source://gco/config/.pre-commit-config.yaml` — Pre-commit hooks") 

28 lines.append("\n## Security & Linting") 

29 for name in ( 

30 ".checkov.yaml", 

31 ".kics.yaml", 

32 ".gitleaks.toml", 

33 ".semgrepignore", 

34 ".yamllint.yml", 

35 ): 

36 lines.append(f"- `source://gco/config/{name}` — {name}") 

37 lines.append("\n## CDK Configuration") 

38 lines.append("- `source://gco/config/cdk.json` — CDK deployment configuration") 

39 lines.append("- `source://gco/config/app.py` — CDK app entry point") 

40 lines.append( 

41 "- `source://gco/config/pyproject.toml` — Python project metadata and dependencies" 

42 ) 

43 lines.append("\n## Related Resources") 

44 lines.append("- `scripts://gco/index` — Utility scripts for operations") 

45 lines.append("- `demos://gco/index` — Demo walkthroughs and scripts") 

46 return "\n".join(lines) 

47 

48 

49@mcp.resource("infra://gco/dockerfiles/{filename}") 

50def dockerfile_resource(filename: str) -> str: 

51 """Read a Dockerfile, requirements file, or README for a GCO service.""" 

52 path = DOCKERFILES_DIR / filename 

53 if not path.is_file(): 

54 available = sorted(f.name for f in DOCKERFILES_DIR.iterdir() if f.is_file()) 

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

56 return path.read_text() 

57 

58 

59@mcp.resource("infra://gco/helm/charts.yaml") 

60def helm_charts_resource() -> str: 

61 """Read the Helm charts configuration (chart names, versions, values).""" 

62 if not HELM_CHARTS_FILE.is_file(): 62 ↛ 63line 62 didn't jump to line 63 because the condition on line 62 was never true

63 return "charts.yaml not found." 

64 return HELM_CHARTS_FILE.read_text()