This is the canonical contract for trader-mcp strategies.
A strategy defines behavior. It does not own persistence, lifecycle, or UI rendering.
It must also expose a Hermes-facing report() snapshot with only decision-relevant data.
class Strategy:
LABEL = "Human readable name"
CONFIG_SCHEMA = {}
STATE_SCHEMA = {}
TICK_MINUTES = 1.0
def __init__(self, context, config):
self.context = context
self.config = config
self.state = self.init()
self.stateCONFIG_SCHEMA is declarative metadataself.state belongs to the instanceSTATE_SCHEMA declares what state is durable / persistedinit() -> state created
on_tick() -> state updated
reload -> state restored from engine snapshot if available
The context is capability-only.
Allowed:
account_id and client_id into exec callsNot allowed:
Market regime is a data-layer artifact provided by crypto-mcp, not a Trader-owned query result.
Strategies return structured widgets, not HTML.
{
"widgets": [
{"type": "metric", "label": "PnL", "value": 123.45},
{"type": "line_chart", "data": [...]}
]
}
from src.trader_mcp.strategy_sdk import Strategy
class Strategy(Strategy):
LABEL = "Hello World"
CONFIG_SCHEMA = {"label": {"type": "string", "default": "hello world"}}
STATE_SCHEMA = {"counter": {"type": "int", "default": 0}}
def init(self):
return {"counter": 0}