Coverage for gco_mcp/resources/clients.py: 94.12%
24 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-30 21:22 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-30 21:22 +0000
1"""API client example resources (clients:// scheme) for the GCO MCP server."""
3from cli_runner import PROJECT_ROOT # runtime-resolved checkout root (uvx-safe)
4from server import mcp
6CLIENT_EXAMPLES_DIR = PROJECT_ROOT / "docs" / "client-examples"
7_CLIENT_EXTENSIONS = {".py", ".sh", ".md"}
10@mcp.resource("clients://gco/index")
11def clients_index() -> str:
12 """List API client examples for interacting with the GCO API Gateway."""
13 lines = ["# API Client Examples\n"]
14 lines.append("- `clients://gco/README` — Overview, setup, and API reference\n")
15 for f in sorted(CLIENT_EXAMPLES_DIR.iterdir()):
16 if f.is_file() and f.suffix in _CLIENT_EXTENSIONS and f.name != "README.md":
17 desc = f.stem.replace("_", " ").title()
18 lines.append(f"- `clients://gco/{f.name}` — {desc}")
19 return "\n".join(lines)
22@mcp.resource("clients://gco/{filename}")
23def client_example_resource(filename: str) -> str:
24 """Read an API client example file."""
25 path = CLIENT_EXAMPLES_DIR / filename
26 if not path.is_file():
27 path = CLIENT_EXAMPLES_DIR / f"{filename}.md"
28 if not path.is_file():
29 available = sorted(f.name for f in CLIENT_EXAMPLES_DIR.iterdir() if f.is_file())
30 return f"Client example '{filename}' not found. Available:\n" + "\n".join(available)
31 if path.suffix not in _CLIENT_EXTENSIONS: 31 ↛ 32line 31 didn't jump to line 32 because the condition on line 31 was never true
32 return f"File type '{path.suffix}' not served."
33 return path.read_text()