Coverage for mcp/resources/costs.py: 100%
14 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"""Cost summary resources (costs://gco/...) for the GCO MCP server.
3Wraps ``gco costs summary --days N`` so an LLM can pin a cost window
4URI (e.g. ``costs://gco/summary/30``) and pull the same payload the
5``cost_summary`` tool returns. The number lives in the path so each
6window has its own pinnable resource — handy when comparing 7-day,
730-day, and 90-day pictures across turns.
8"""
10from __future__ import annotations
12import json
13from typing import Any
15import cli_runner
18def _summary_resource(days_window: str) -> str:
19 """Return the cost summary for a positive-integer day window."""
20 try:
21 days = int(days_window)
22 except TypeError, ValueError:
23 return json.dumps({"error": "days_window must be a positive integer", "value": days_window})
24 if days <= 0:
25 return json.dumps({"error": "days_window must be a positive integer", "value": days_window})
26 return cli_runner._run_cli("costs", "summary", "--days", str(days))
29def register(mcp_instance: Any) -> None:
30 """Register the cost summary resource against the shared MCP server."""
31 mcp_instance.resource("costs://gco/summary/{days_window}")(_summary_resource)