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

43 statements  

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

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

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/.pre-commit-config.yaml` — Pre-commit hooks") 

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

28 for name in ( 

29 ".checkov.yaml", 

30 ".kics.yaml", 

31 ".gitleaks.toml", 

32 ".semgrepignore", 

33 ".yamllint.yml", 

34 ): 

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

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

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

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

39 lines.append( 

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

41 ) 

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

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

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

45 return "\n".join(lines) 

46 

47 

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

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

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

51 path = DOCKERFILES_DIR / filename 

52 if not path.is_file(): 

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

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

55 return path.read_text() 

56 

57 

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

59def helm_charts_resource() -> str: 

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

61 if not HELM_CHARTS_FILE.is_file(): 

62 return "charts.yaml not found." 

63 return HELM_CHARTS_FILE.read_text()