base
ipw.agents.mcp.base
¶
Base MCP server with telemetry integration.
All MCP servers (local models, cloud APIs, tools) inherit from BaseMCPServer, which automatically captures energy, power, cost, and latency metrics around every execution.
MCPToolResult
dataclass
¶
Result from MCP tool execution with telemetry.
Source code in intelligence-per-watt/src/ipw/agents/mcp/base.py
content
instance-attribute
¶
Response text from tool/model
usage = field(default_factory=dict)
class-attribute
instance-attribute
¶
Token counts: prompt_tokens, completion_tokens, total_tokens
cost_usd = None
class-attribute
instance-attribute
¶
API cost in USD (for cloud APIs)
telemetry_samples = field(default_factory=list)
class-attribute
instance-attribute
¶
Energy/power/memory readings during execution
latency_seconds = 0.0
class-attribute
instance-attribute
¶
Wall-clock execution time
ttft_seconds = None
class-attribute
instance-attribute
¶
Time to first token (for streaming APIs)
metadata = field(default_factory=dict)
class-attribute
instance-attribute
¶
Additional tool-specific metadata
BaseMCPServer
¶
Bases: ABC
Base class for all MCP servers with automatic telemetry capture.
All subclasses must implement _execute_impl() which performs the actual tool invocation. The base class wraps this with telemetry collection.
Example
class MyTool(BaseMCPServer): def _execute_impl(self, prompt: str, **params) -> MCPToolResult: response = self.api.call(prompt) return MCPToolResult( content=response.text, usage={"prompt_tokens": 100, "completion_tokens": 50}, cost_usd=0.001 )
Source code in intelligence-per-watt/src/ipw/agents/mcp/base.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
__init__(name, telemetry_collector=None, event_recorder=None)
¶
Initialize MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name for logging/tracking |
required |
telemetry_collector
|
Optional[Any]
|
Energy monitor collector. If None, runs without telemetry. |
None
|
event_recorder
|
Optional[Any]
|
EventRecorder for per-action tracking. If None, no events recorded. |
None
|
Source code in intelligence-per-watt/src/ipw/agents/mcp/base.py
execute(prompt, **params)
¶
Execute tool with automatic telemetry capture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Input prompt/query for tool |
required |
**params
|
Any
|
Additional tool-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
MCPToolResult
|
MCPToolResult with content, usage, cost, and telemetry samples |
Source code in intelligence-per-watt/src/ipw/agents/mcp/base.py
health_check()
¶
Check if tool is available and healthy.
Returns:
| Type | Description |
|---|---|
bool
|
True if tool is operational, False otherwise |