Integration
MCP Server
Expose the SDK to any MCP client so an agent can author and run backtests, research markets, and pull order book data and surfaces in natural language. Optional extra, no effect on the base install.
Setup
Install the optional extra and add the server to your MCP client config. It runs locally over stdio and authenticates with your API key, the same one the SDK and REST API use.
Works with Claude Code, Claude Desktop, Cursor, and any other MCP client. Compose it alongside other servers (arxiv, web search, filesystem) so agents can read the literature, pull data, and backtest in a single session.
bash
$ pip install 'marketlens[mcp]'# or python -m marketlens.mcpjsonmcp client config
{
"mcpServers": {
"marketlens": {
"command": "marketlens-mcp",
"env": { "MARKETLENS_API_KEY": "mk_..." }
}
}
}Tools
Data tools wrap the typed resources; list tools return compact rows capped at 200 per call.
Data
search_markets, get_market
Find and inspect markets.
search_events, search_series
Browse events and recurring series.
get_orderbook
Point-in-time L2 book with spread, microprice, and imbalance.
get_orderbook_metrics
Time-bucketed book metrics over a window.
get_trades, get_candles
Executed trades and OHLCV.
get_reference_candles
Binance spot for the underlying asset.
get_signals, get_surface
Implied probability surfaces.
Backtesting
strategy_reference
The Strategy / StrategyContext API, so the agent writes correct code.
run_backtest
Run agent-authored strategy code through the engine. Returns metrics and a saved result path.
compare_backtests
Score several strategies over one target and window side by side.
open_backtest
Inspect a saved run's metrics, per-series PnL, and settlement ledger without re-running.
Environment
MARKETLENS_API_KEYrequired
Your API key. Authenticates every tool call.
MARKETLENS_MCP_DISABLE_BACKTEST
Set to 1 to disable local strategy execution.
agent session
user
Backtest a mean-reversion entry on
btc-up-or-down-5m: go long YES when the
midpoint dislocates below 0.35, size 200
shares, then liquidate at resolution. Replay
2026-04-15 12:00 to 18:00 UTC, $10,000 capital.
agent
strategy_reference()
run_backtest(
"btc-up-or-down-5m",
after="2026-04-15T12:00:00Z",
before="2026-04-15T18:00:00Z",
initial_cash=10_000,
data_dir="data",
)
total_return +4.1%
win_rate 58%
sharpe 1.9
saved → runs/btc-dip-buyer