Coverage for mcp/resources/infra.py: 93%
45 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"""Infrastructure config resources (infra:// scheme) for the GCO MCP server."""
3from pathlib import Path
5from server import mcp
7PROJECT_ROOT = Path(__file__).parent.parent.parent
8DOCKERFILES_DIR = PROJECT_ROOT / "dockerfiles"
9HELM_CHARTS_FILE = PROJECT_ROOT / "lambda" / "helm-installer" / "charts.yaml"
12@mcp.resource("infra://gco/index")
13def infra_index() -> str:
14 """List infrastructure configuration files — Dockerfiles, Helm charts, CI/CD."""
15 lines = ["# Infrastructure Configuration\n"]
16 lines.append("## Dockerfiles")
17 readme = DOCKERFILES_DIR / "README.md"
18 if readme.is_file(): 18 ↛ 20line 18 didn't jump to line 20 because the condition on line 18 was always true
19 lines.append("- `infra://gco/dockerfiles/README.md` — Dockerfiles overview")
20 for f in sorted(DOCKERFILES_DIR.iterdir()):
21 if f.is_file() and not f.name.startswith(".") and f.name != "README.md":
22 lines.append(f"- `infra://gco/dockerfiles/{f.name}`")
23 lines.append("\n## Helm Charts")
24 if HELM_CHARTS_FILE.is_file(): 24 ↛ 26line 24 didn't jump to line 26 because the condition on line 24 was always true
25 lines.append("- `infra://gco/helm/charts.yaml` — Helm chart versions and config")
26 lines.append("\n## CI/CD")
27 lines.append("- `ci://gco/index` — GitHub Actions workflows, composite actions, scripts")
28 lines.append("- `source://gco/config/.gitlab-ci.yml` — GitLab CI pipeline (frozen reference)")
29 lines.append("- `source://gco/config/.pre-commit-config.yaml` — Pre-commit hooks")
30 lines.append("\n## Security & Linting")
31 for name in (
32 ".checkov.yaml",
33 ".kics.yaml",
34 ".gitleaks.toml",
35 ".semgrepignore",
36 ".yamllint.yml",
37 ):
38 lines.append(f"- `source://gco/config/{name}` — {name}")
39 lines.append("\n## CDK Configuration")
40 lines.append("- `source://gco/config/cdk.json` — CDK deployment configuration")
41 lines.append("- `source://gco/config/app.py` — CDK app entry point")
42 lines.append(
43 "- `source://gco/config/pyproject.toml` — Python project metadata and dependencies"
44 )
45 lines.append("\n## Related Resources")
46 lines.append("- `scripts://gco/index` — Utility scripts for operations")
47 lines.append("- `demos://gco/index` — Demo walkthroughs and scripts")
48 return "\n".join(lines)
51@mcp.resource("infra://gco/dockerfiles/{filename}")
52def dockerfile_resource(filename: str) -> str:
53 """Read a Dockerfile, requirements file, or README for a GCO service."""
54 path = DOCKERFILES_DIR / filename
55 if not path.is_file():
56 available = sorted(f.name for f in DOCKERFILES_DIR.iterdir() if f.is_file())
57 return f"File '{filename}' not found. Available:\n" + "\n".join(available)
58 return path.read_text()
61@mcp.resource("infra://gco/helm/charts.yaml")
62def helm_charts_resource() -> str:
63 """Read the Helm charts configuration (chart names, versions, values)."""
64 if not HELM_CHARTS_FILE.is_file(): 64 ↛ 65line 64 didn't jump to line 65 because the condition on line 64 was never true
65 return "charts.yaml not found."
66 return HELM_CHARTS_FILE.read_text()