Coverage for mcp/resources/clients.py: 94%

25 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-15 15:07 +0000

1"""API client example resources (clients:// scheme) for the GCO MCP server.""" 

2 

3from pathlib import Path 

4 

5from server import mcp 

6 

7PROJECT_ROOT = Path(__file__).parent.parent.parent 

8CLIENT_EXAMPLES_DIR = PROJECT_ROOT / "docs" / "client-examples" 

9_CLIENT_EXTENSIONS = {".py", ".sh", ".md"} 

10 

11 

12@mcp.resource("clients://gco/index") 

13def clients_index() -> str: 

14 """List API client examples for interacting with the GCO API Gateway.""" 

15 lines = ["# API Client Examples\n"] 

16 lines.append("- `clients://gco/README` — Overview, setup, and API reference\n") 

17 for f in sorted(CLIENT_EXAMPLES_DIR.iterdir()): 

18 if f.is_file() and f.suffix in _CLIENT_EXTENSIONS and f.name != "README.md": 

19 desc = f.stem.replace("_", " ").title() 

20 lines.append(f"- `clients://gco/{f.name}` — {desc}") 

21 return "\n".join(lines) 

22 

23 

24@mcp.resource("clients://gco/{filename}") 

25def client_example_resource(filename: str) -> str: 

26 """Read an API client example file.""" 

27 path = CLIENT_EXAMPLES_DIR / filename 

28 if not path.is_file(): 

29 path = CLIENT_EXAMPLES_DIR / f"{filename}.md" 

30 if not path.is_file(): 

31 available = sorted(f.name for f in CLIENT_EXAMPLES_DIR.iterdir() if f.is_file()) 

32 return f"Client example '{filename}' not found. Available:\n" + "\n".join(available) 

33 if path.suffix not in _CLIENT_EXTENSIONS: 33 ↛ 34line 33 didn't jump to line 34 because the condition on line 33 was never true

34 return f"File type '{path.suffix}' not served." 

35 return path.read_text()