MCPcopy Create free account
hub / github.com/IBM/mcp-cli / UsageCommand

Class UsageCommand

src/mcp_cli/commands/usage/usage.py:14–63  ·  view source on GitHub ↗

Display token usage statistics.

Source from the content-addressed store, hash-verified

12
13
14class UsageCommand(UnifiedCommand):
15 """Display token usage statistics."""
16
17 @property
18 def name(self) -> str:
19 return "usage"
20
21 @property
22 def aliases(self) -> list[str]:
23 return ["tokens", "cost"]
24
25 @property
26 def description(self) -> str:
27 return "Show token usage statistics"
28
29 @property
30 def help_text(self) -> str:
31 return """
32Show token usage statistics for the current session.
33
34Usage:
35 /usage - Display per-turn and cumulative token counts
36
37Aliases: /tokens, /cost
38"""
39
40 @property
41 def modes(self) -> CommandMode:
42 return CommandMode.CHAT
43
44 @property
45 def parameters(self) -> list:
46 return []
47
48 async def execute(self, **kwargs) -> CommandResult:
49 """Execute the usage command."""
50 chat_context = kwargs.get("chat_context")
51 if not chat_context:
52 return CommandResult(success=False, error="No chat context available.")
53
54 tracker = getattr(chat_context, "token_tracker", None)
55 if tracker is None or tracker.turn_count == 0:
56 output.info("No token usage recorded yet.")
57 return CommandResult(success=True, output="No usage data.")
58
59 # Format summary
60 summary = tracker.format_summary()
61 output.panel(summary, title="Token Usage")
62
63 return CommandResult(success=True, output=summary)

Callers 2

register_all_commandsFunction · 0.90
cmdFunction · 0.90

Calls

no outgoing calls

Tested by 1

cmdFunction · 0.72